簡體   English   中英

Azure AD B2C授權代碼流-訪問graph.windows.net

[英]Azure AD B2C authorization code flow - accessing graph.windows.net

我使用Azure AD B2C 授權代碼流 (下面在URL和表單內容中插入換行符以提高可見性)。

首先,我在瀏覽器中打開以下URL:

https://mycompany.b2clogin.com/mycompany.onmicrosoft.com/oauth2/v2.0/authorize?
client_id=8acddeb9-e950-4d64-802c-dcc9fab4f89b&
response_type=code&
redirect_uri=https%3A%2F%2Fmy-company-site.com%2F&
response_mode=query&
scope=8acddeb9-e950-4d64-802c-dcc9fab4f89b%20offline_access%20openid&
state=arbitrary_data_you_can_receive_in_the_response&
p=B2C_susi_test

輸入憑據后,我將重定向到

https://my-company-site.com/?
state=arbitrary_data_you_can_receive_in_the_response&
code=__authorization_code__

之后,我嘗試請求access_token (這里是https://graph.windows.net/ ):

POST https://mycompany.b2clogin.com/mycompany.onmicrosoft.com/oauth2/v2.0/token?p=B2C_susi_test
User-Agent: Fiddler
Host: mycompany.b2clogin.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&
client_id=8acddeb9-e950-4d64-802c-dcc9fab4f89b
scope=openid+offline_access&
code=__authorization_code__&
redirect_uri=https%3A%2F%2Fmy-company-site.com%2F&
client_secret=__client_secret__&
resource=https%3A%2F%2Fgraph.windows.net%2F

結果,我得到以下JSON:

{
    "id_token": "__a_token__",
    "token_type": "Bearer",
    "not_before": 1564662310,
    "id_token_expires_in": 3600,
    "profile_info": "__some_info__",
    "refresh_token": "__refresh_token___",
    "refresh_token_expires_in": 1209600
}

首先,這里缺少access_token ,但是有id_token ,它與docs不同。

然后我嘗試使用id_token訪問https://graph.windows.net

GET https://graph.windows.net/mycompany/users/me?api-version=1.6 HTTP/1.1
User-Agent: Fiddler
Host: graph.windows.net
Authorization: Bearer __a_token__

響應(401):

{
    "odata.error": {
        "code": "Authentication_ExpiredToken",
        "message": {
            "lang": "en",
            "value": "Your access token has expired. Please renew it before submitting the request."
        }
    }
}

關於令牌為何是access_token任何想法都丟失了,或者如何使用id_token

您不能使用AAD B2C應用程序注冊和B2C用戶旅程訪問任何Microsoft第一方服務。

如果您需要訪問Microsoft服務,請使用AAD應用程序注冊和AAD流程。

在B2C場景中,Web服務器需要訪問Graph API,讓Web服務器針對B2C目錄中的AAD應用注冊使用客戶端憑據流。

您無法使用Azure AD B2C流獲取Azure AD Graph API的訪問令牌-因為此API並非Azure AD B2C注冊的應用程序。

您必須使用Azure AD流獲取它

暫無
暫無

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

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