簡體   English   中英

為 localhost 設置 Microsoft Identify Platform 和“Missing grant for this add-in”

[英]Setup Microsoft Identify Platform and "Missing grant for this add-in" for localhost

我有一個實現單點登錄的 Excel 加載項,但最近我意識到 SSO 不再起作用。 所以我嘗試在本地主機上調試它。

首先,我在我的加載項中遇到了Missing grant for this add-in 然后,我在示例項目中遇到了同樣的錯誤: https://learn.microsoft.com/en-us/office/dev/add-ins/quickstarts/sso-quickstart 請注意,我沒有https://learn.microsoft.com/en-us/office/dev/add-ins/develop/create-sso-office-add-ins-nodejs的錯誤。

我創建了一個測試 Azure 帳戶: test.sso.2023@gmail.com並注冊了該應用程序 我將產生錯誤的sso-quickstart的更新代碼放入此存儲庫中。

啟動代碼后,我們可以在 Chrome 中在線登錄 Excel,然后旁加載加載項。 單擊按鈕Get My User Profile Information啟動Office.auth.getAccessToken ,這引發了錯誤POST https://login.microsoftonline.com/consumers/oauth2/v2.0/token 400 (Bad Request)Missing grant for this add-in.

在此處輸入圖像描述

返回的請求https://login.microsoftonline.com/consumers/oauth2/v2.0/token

AADSTS70000:請求被拒絕,因為請求的一個或多個范圍未經授權或已過期。 用戶必須首先登錄並授予客戶端應用程序訪問所請求的 scope...

在此處輸入圖像描述

我在Microsoft Identity Platform上設置的JSON:

{
    "id": "f61962fb-722b-465f-a265-4a1e70a744e3",
    "acceptMappedClaims": null,
    "accessTokenAcceptedVersion": 2,
    "addIns": [],
    "allowPublicClient": null,
    "appId": "e55f4769-4293-4b71-94ea-5eb16dcfe41d",
    "appRoles": [],
    "oauth2AllowUrlPathMatching": false,
    "createdDateTime": "2023-01-31T19:16:20Z",
    "description": null,
    "certification": null,
    "disabledByMicrosoftStatus": null,
    "groupMembershipClaims": null,
    "identifierUris": [
        "api://localhost:3000/e55f4769-4293-4b71-94ea-5eb16dcfe41d"
    ],
    "informationalUrls": {
        "termsOfService": null,
        "support": null,
        "privacy": null,
        "marketing": null
    },
    "keyCredentials": [],
    "knownClientApplications": [],
    "logoUrl": null,
    "logoutUrl": null,
    "name": "sso",
    "notes": null,
    "oauth2AllowIdTokenImplicitFlow": false,
    "oauth2AllowImplicitFlow": false,
    "oauth2Permissions": [
        {
            "adminConsentDescription": "Allow Office to have read/write permissions to all user files and read permissions to all user mail. Office can call the app's web APIs as the current user.",
            "adminConsentDisplayName": "Read/write permissions to user files. Read permissions to user mail and profiles.",
            "id": "9b6c01b1-9818-4eb3-898c-e412fad8ae03",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "type": "User",
            "userConsentDescription": "Allow Office to have read/write permissions to your files, and read permissions to your mail and profile.",
            "userConsentDisplayName": "Read/write permissions to your files. Read permissions to your mail and profile.",
            "value": "access_as_user"
        }
    ],
    "oauth2RequirePostResponse": false,
    "optionalClaims": null,
    "orgRestrictions": [],
    "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
    },
    "passwordCredentials": [
        {
            "customKeyIdentifier": null,
            "endDate": "2023-07-30T18:17:18.762Z",
            "keyId": "10c2239b-b83c-4085-b277-a37931990aa1",
            "startDate": "2023-01-31T19:17:18.762Z",
            "value": null,
            "createdOn": "2023-01-31T19:17:25.3206496Z",
            "hint": "~l2",
            "displayName": "secret"
        }
    ],
    "preAuthorizedApplications": [
        {
            "appId": "ea5a67f6-b6f3-4338-b240-c655ddc3cc8e",
            "permissionIds": [
                "9b6c01b1-9818-4eb3-898c-e412fad8ae03"
            ]
        },
        {
            "appId": "d3590ed6-52b3-4102-aeff-aad2292ab01c",
            "permissionIds": [
                "9b6c01b1-9818-4eb3-898c-e412fad8ae03"
            ]
        },
        {
            "appId": "93d53678-613d-4013-afc1-62e9e444a0a5",
            "permissionIds": [
                "9b6c01b1-9818-4eb3-898c-e412fad8ae03"
            ]
        }
    ],
    "publisherDomain": null,
    "replyUrlsWithType": [
        {
            "url": "https://localhost:3000/fallbackauthdialog.html",
            "type": "Spa"
        }
    ],
    "requiredResourceAccess": [
        {
            "resourceAppId": "00000003-0000-0000-c000-000000000000",
            "resourceAccess": [
                {
                    "id": "14dad69e-099b-42c9-810b-d002981feec1",
                    "type": "Scope"
                },
                {
                    "id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
                    "type": "Scope"
                },
                {
                    "id": "37f7f235-527c-4136-accd-4a02d197296e",
                    "type": "Scope"
                }
            ]
        }
    ],
    "samlMetadataUrl": null,
    "signInUrl": null,
    "signInAudience": "AzureADandPersonalMicrosoftAccount",
    "tags": [],
    "tokenEncryptionKeyId": null
}

而API權限也可以在上面的JSON中找到:

在此處輸入圖像描述

有誰知道這個錯誤的原因可能是什么?

(*鏈接在 Github office-js *)

重定向 URI:https://localhost:3000(應該是 https://localhost:3000 還是 https://localhost:8000?)

當然。 localhost:3000 上沒有任何運行。 一切都應該使用相同的 URL。

無論如何,我建議嘗試創建一個空加載項並使用自動工具在 Azure 中注冊 web 加載項。按照這種方式,您可以確保 SSO 為您的租戶正常工作,並且警告顯示在如果示例加載項工作正常,屏幕截圖與此無關。 然后,您可以開始更深入地研究現有解決方案以找到根本原因。

configure-sso NPM package 可以幫助正確設置示例加載項。 有關指南,請參閱單點登錄 (SSO) 快速入門。

我試圖在我的環境中重現相同的結果並得到以下結果:

我運行了以下命令,通過選擇所需選項,使用 JavaScript 和單點登錄為Excel創建My Office Add-in

npm install -g yo generator-office
yo office

回復:

在此處輸入圖像描述

現在我運行npm run configure-sso將我帶到瀏覽器,我在其中選擇了一個用戶憑據:

在此處輸入圖像描述

登錄成功后,我得到 output 說新應用程序已在 Azure AD 中成功注冊並自動更新文件,如下所示:

在此處輸入圖像描述

當我在門戶中檢查相同內容時,Azure AD 應用程序已成功注冊,詳情如下:

在此處輸入圖像描述

我將以下API 權限自動添加到應用程序中,如下所示:

在此處輸入圖像描述

當我檢查Expose an API選項卡時,它在下面添加了詳細信息,例如 App ID URI、范圍等...

在此處輸入圖像描述

我在我的應用程序中添加了以下重定向 URI

在此處輸入圖像描述

當我運行npm start命令時,它最初要求安裝證書,如下所示:

在此處輸入圖像描述

這使用My Office Add-in其中獲得了如下所示的同意屏幕

在此處輸入圖像描述

同意權限后,我成功獲得了用戶個人資料詳細信息,如下所示:

在此處輸入圖像描述

在您的情況下,請確保擁有一個 Azure 帳戶和有效的 Azure 訂閱,並將Global administrator角色分配給該租戶的測試用戶帳戶,這是同意權限所必需的。

如果您沒有有效的 Azure 帳戶,請單擊此鏈接中的Start free按鈕獲取免費試用訂閱。

現在,通過使用此用戶憑據再次配置加載項來重復整個過程。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM