0

我正在使用 Office-js-helpers 和 Office.context.ui.displayDialogAsync 在我们的 Outlook 加载项中对用户进行身份验证。对话框打开很好,我可以使用我们的 IdentityServer4 url​​ 进行身份验证(例如 /connect/authenticate 与 redirectUrl window.location.origin)。但是,如果我的加载项文件夹中没有 Index.html,我会在 DialogEventReceived 处理程序中收到 12002 错误,这意味着对话框无法加载 url。如果我在我的加载项文件夹中添加 Index.html(例如 window.location.origin 将是https://localhost:44352/Index.html ) ,我不会收到此错误- 但没有任何反应。DialogMessageReceived 句柄永远不会触发。我使用 office-js 的 Authenticator.authenticate 和 displayDialogAsync 得到了同样的行为。

请参阅下面的片段,这些片段在对话框中验证良好,但我无法获取令牌/代码,因为 DialogMessageReceived 永远不会触发或出错。

使用 Office-js-helpers

authenticator.endpoints.add("RM", {
                provider: 'RM',
                clientId: "MyClientId",
                baseUrl: "MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer",
                authorizeUrl: "/connect/authorize",
                tokenUrl: "MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer/connect/token",
                redirectUrl: window.location.origin,    
                responseType: "code",
                state: true,
                scope: "openid profile onelist offline_access"
            });

authenticator.authenticate('RM', true)
                        .then(function (token) {
                            showNotification("Token: " + prettify(token));
                        })
                        .catch(function (error) {
                            showNotification("No Token: " + prettify(error));
                        });

使用对话框 API

Office.context.ui.displayDialogAsync("MyHttpsProtocol://MyDomain.DotCom/MyIdentityServer/connect/authorize?response_type=code&client_id=MyClientID&redirect_uri=https%3A%2F%2Flocalhost%3A44352&scope=openid%20profile%20MyProfile%20offline_access&state=3364575774",
                        { height: 500, width: 500 }, 
                            function (asyncResult) {
                                dialog = asyncResult.value;
                                dialog.addEventHandler(Office.EventType.DialogMessageReceived, function (args) {
                                    showNotification(prettify(args.message));
                                    dialog.close();
                                });
                                dialog.addEventHandler(Office.EventType.DialogEventReceived, function (args) {
                                    showNotification(prettify(args.error));
                                    dialog.close();
                                });
                            }
                        );

请帮助:)我错过了什么或做错了什么?

4

0 回答 0