首页 > 解决方案 > 在 Outlook 365 Web 插件 13005 中获取 SSO 时出错。缺少预授权

问题描述

我正在开发一个 Outlook 加载项,我正在尝试获取 SSO 令牌来调用 Graph API。我指的是这个链接来开发我的插件Outlook 插件 SSO。我在 Azure AD(多租户)中注册了我的应用程序。一步一步地跟随一切

我将版本覆盖添加到清单

  <Id>Client_id-xxx-xxx</Id>
  <Resource>api://localhost:44361/Client_id-xxx-xxx</Resource>
  <Scopes>
    <Scope>openid</Scope>
    <Scope>offline_access</Scope>
    <Scope>profile</Scope>
    <Scope>Files.ReadWrite</Scope>
    <Scope>Mail.Read</Scope>
    <Scope>User.Read</Scope>
    <Scope>email</Scope>
  </Scopes>
</WebApplicationInfo>

authconfig.js

var authConfig = {
    
    clientId:"Client_id-xxx-xxx",
    scopes: "Files.ReadWrite Mail.Read openid offline_access profile email User.Read",
    redirectUrl: "https://localhost:44361/MessageRead.html"
};

网页配置

<appSettings>
    <add key="ida:AppId" value="Client_Id_xx-xx" />
    <add key="ida:Audience" value="Client_id_xx_xx" />
    <add key="ida:AppPassword" value="app_Password" />
    <add key="ida:RedirectUri" value="https://localhost:44361/MessageRead.html" />
    <add key="ida:Authority" value="https://login.microsoftonline.com/common/oauth2/v2.0" />
  </appSettings>

我也已向租户中的所有用户授予管理员同意。(详见附件) 授予管理员同意

我的 JavaScript 代码:

Office.initialize = function (reason) {
     //   console.log("In Office.initialize ", reason);
        $(document).ready(function () {
       //     console.log("In Office.ready ");
            if (OfficeHelpers.Authenticator.isAuthDialog()) return;
            var element = document.querySelector('.ms-MessageBanner');
            messageBanner = new fabric.MessageBanner(element);
            messageBanner.hideBanner();

            authenticator = new OfficeHelpers.Authenticator();
            authenticator.endpoints.registerMicrosoftAuth(authConfig.clientId, {
                redirectUrl: authConfig.redirectUrl,
                scope: authConfig.scopes
            });

            //loadProps();

        });
    };

    function GetSSOToken(DataObj) {
            var attachmentIds = getAttechamentIdList();
            //if (Office.context.auth !== undefined && Office.context.auth.getAccessToken !== undefined) {
            if (OfficeRuntime.auth !== undefined && OfficeRuntime.auth.getAccessToken !== undefined) {
            
                OfficeRuntime.auth.getAccessToken().then(function (result) {
                    if (result.status === "succeeded") {
                       
                        // No need to prompt user, use this token to call Web API 
                        saveEmailWithSSO(result.value, attachmentIds, DataObj);
                    } else if (result.error.code == 13007 || result.error.code == 13005) {
                        console.log('error:', result.error.code);
                        // These error codes indicate that we need to prompt for consent
                        // Office.context.auth.getAccessTokenAsync({ forceConsent: true }, function (result) {
                        
                        OfficeRuntime.auth.getAccessToken({ allowConsentPrompt: true, allowSignInPrompt: true }, function (result) {
                            if (result.status === "succeeded") {
                                console.log('AccessToken:', result.value);
                                saveEmailWithSSO(result.value, attachmentIds, DataObj);
                            } else {
                                // Could not get SSO token, proceed with authentication prompt
                                console.log('in with prompt else1 ');
                                // console.log('error:', result.error.code);
    
                                saveEmailWithPrompt(attachmentIds);
    
                               
                            }
                        });
                    } else {
                        // Could not get SSO token, proceed with authentication prompt
                      
                        console.log('in with prompt else2 ');
                        console.log('error:', result.error.code);
                        saveEmailWithPrompt(attachmentIds);
    
                    }
                }).catch(function (error) {
                    console.log('in catch', error);  
                });
            } 

上面的代码总是在 Catch 块中结束,错误 13005,缺少预授权,缺少此插件的授权。

我已经参考并从此链接进行了更改https://github.com/OfficeDev/office-js/issues/923 即使这里的类似问题也无法解决。请建议还有什么可以解决的。

我正在尝试使用全局管理员的 Outlook 帐户和来自外部租户的另一个用户运行此代码。但在这两种情况下都不起作用。

- - - 更新 - -

经过一些工作后,我可以在登录时看到这个问题(在使用 forceConsent allowConsentPrompt 时)AADSTS90008我可以看到这个错误

标签: oauth-2.0microsoft-graph-apisingle-sign-onazure-ad-graph-apioutlook-web-addins

解决方案


解决了 !经过数小时的头脑风暴,我能够通过再次修改文档来解决此错误。我忽略了https://docs.microsoft.com/en-us/office/dev/add-ins/develop/register-sso-add-in-aad-v2的第 12 步在此处输入图像描述


推荐阅读