我想查询用户的群组。根据{{3}},我执行以下步骤:
获取代码
https://login.microsoftonline.com/common/oauth2/authorize?
response_type=id_token%20code&
client_id=<MY_CLIENT_ID>&
redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fopenid%2Freturn
response_mode=query&
nonce=F8GtCajiXYKcGBtw&
scope=openid%20https%3A%2F%2Fgraph.microsoft.com%2FGroup.Read.All%20Group.Read.All&
resource=https%3A%2F%2Fgraph.microsoft.com%2F&
state=HTlUWuV5su%2BG4zBE#
注意:提供了3个范围(openid,Group.Read.All,https://graph.microsoft.io/en-us/docs/platform/rest)
然后我登录,AAD回复我的网站:
http://localhost:3000/auth/openid/return?
code=<Recieved_Code>&
id_token=<Recieved_id_Token>&
state=xxxx&
session_state=yyy
POST https://login.microsoftonline.com/common/oauth2/token Content-Type: application/x-www-form-urlencoded { grant_type=authorization_code &code=Recieved_Code_from_step_1 &redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fopenid%2Freturn &resource=https%3A%2F%2Fgraph.microsoft.com%2F &client\_id= &client\_secret= }
然后返回JSON
{
"token_type":"Bearer",
"scope":"User.Read",
"resource":"https://graph.microsoft.com/",
"access_token":<Access_token_in_here>,
... other fields
}
注意:仅返回User.Read范围
我使用步骤2中的access_token进行查询
那么为什么我要求3个范围的许可,但只获得一个范围的许可?
答案 0 :(得分:0)
您的请求正在使用v1端点。此端点不接受作为请求一部分的作用域。使用v1,您需要在Azure Active Directory中存储的注册记录中预先配置所需的范围。
我建议切换到v2。这将允许您在代码中声明范围并大大简化注册过程。