1

我正在尝试使用 Visual Studio 2019 中的 office-js-helpers 在 .NET Core 2.2 上使用 IdentityServer4 对 Excel Web 加载项(自定义功能)进行身份验证

  1. 为我自己的 IdentityServer 添加一个端点,我很确定我需要设置一个 clientSecret?但我在端点管理器中找不到有关此的信息。 https://github.com/OfficeDev/office-js-helpers/blob/master/src/authentication/endpoint.manager.ts

使用自定义端点没有成功,我决定尝试使用预设端点的作者代码。假设工作演示位于此处:https ://github.com/OfficeDev/office-js-helpers/tree/master/demo

  1. 在 c/p'ing 演示后:
    • 单击 microsoft login 会打开正确提示输入用户名 + 密码的身份验证对话框,
    • 它验证正常(access_token 显示在 browserurl 中)-但永远不会到达 js 中的回调 then() 以便我可以获得令牌。

有没有人使用office-js-helpers从任何办公室添加oauth2正常工作?(或任何其他图书馆)。

任何帮助表示赞赏。

主要目标是使用我设置的身份服务器进行身份验证。但是现在我只需要使用 office-js-helpers 的作者定义的预设端点的一些工作解决方案。

这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <title>Office Helpers Demo</title>
    <link rel="stylesheet" href="https://unpkg.com/office-ui-fabric-js@1.4.0/dist/css/fabric.min.css" />
    <link rel="stylesheet" href="https://unpkg.com/office-ui-fabric-js@1.4.0/dist/css/fabric.components.min.css" />
    <script src="https://unpkg.com/jquery@3.2.1/dist/jquery.js"></script>
    <script src="https://unpkg.com/core-js@2.5.1/client/core.js"></script>
    <script src="https://unpkg.com/@microsoft/office-js-helpers@1.0.0/dist/office.helpers.min.js"></script>
</head>
<body>
    <button class="login" data-provider="Dropbox">Sign into Dropbox</button>
    <button class="login" data-provider="Microsoft">Sign into Microsoft</button>
    <pre id="output"></pre>
<script>
    (function ($) {

        function prettify(data) {
            let json = JSON.stringify(data);
            json = json.replace(/{/g, "{\n\n\t");
            json = json.replace(/,/g, ",\n\t");
            json = json.replace(/}/g, ",\n\n}");
            return json;
        }

        $("document").ready(function () {
            if (OfficeHelpers.Authenticator.isAuthDialog()) {
                return;
            }

            let output = $("#output");
            let authenticator = new OfficeHelpers.Authenticator();


            authenticator.endpoints.registerMicrosoftAuth("f59e8034-6e3c-4ba6-9fb5-1342d27d0123");
            authenticator.endpoints.registerDropboxAuth("tkvf431lh8d9hci");

            $(".login").click(function () {
                let provider = $(this).data("provider");
                output.text("Authenticating with " + provider + "...");

                authenticator.authenticate(provider, true)
                    .then(function (token) {
                        output.text(prettify(token));
                    })
                    .catch(function (error) {
                        output.text(prettify(error));
                    });
            });
        });
    })(jQuery);
</script>
</body>
</html>
4

0 回答 0