我正在使用bell和 hapijs并试图获得 office365 provider工作,但看起来像 https://login.microsoftonline.com/common/oauth2/v2.0/token端点没有向我提供获取个人资料信息所需的 access_token
。
这是我看到的 OAuth 2.0 流程:
首先它重定向到
https://login.microsoftonline.com/common/oauth2/v2.0/authorize
?client_id=[client-id]
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%3A5430%2Fapi%2Fv1%2Flogin%2Fazure-ad
&state=[state]
&scope=openid%20offline_access%20profile
从 Microsoft 登录成功登录后,它会重定向到服务器,并且 Bell 会向 https://login.microsoftonline.com/common/oauth2/v2.0/token 执行 POST 操作。带负载
{
payload: 'grant_type=authorization_code&code=[code]&redirect_uri=http%3A%2F%2Flocalhost%3A5430%2Fapi%2Fv1%2Flogin%2Fazure-ad&client_id=[client-id]&client_secret=[client-secret]',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
这又给了我以下响应
{
"refresh_token": "MCTrMmd...",
"id_token": "eyJ0eXAiOiJKV..."
}
来自OAuth 2.0 Authorization Code Flow文档,看来我应该得到更像的东西
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5HVEZ2ZEstZnl0aEV1Q...",
"token_type": "Bearer",
"expires_in": 3599,
"scope": "https%3A%2F%2Fgraph.microsoft.com%2Fmail.read",
"refresh_token": "AwABAAAAvPM1KaPlrEqdFSBzjqfTGAMxZGUTdM0t4B4...",
"id_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJhdWQiOiIyZDRkMTFhMi1mODE0LTQ2YTctOD...",
}
具体来说,我需要一个 access_token
,因为以下配置文件获取请求 ( oauth.js#L270 ) 需要它
Authorization: 'Bearer ' + payload.access_token
即使在 Calling /token endpoint does not give me an access_token ,看起来 /token
请求在响应中获得了更多字段。
请求中是否缺少某些内容?
最佳答案
查看您的第一个请求,它没有 response_mode=query
header ,与 documentation 相比:
关于Azure AD v2 登录的 JavaScript OAuth2 流不提供 access_token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49405587/