【发布时间】:2019-12-10 01:34:30
【问题描述】:
我使用 Azure AD B2C authorization code flow(下面我在 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?
【问题讨论】:
标签: oauth-2.0 azure-ad-b2c openid-connect