【问题标题】:Authorization_RequestDenied on setting value for user key object using Microsoft GraphAuthorization_RequestDenied 使用 Microsoft Graph 设置用户密钥对象的值
【发布时间】:2021-05-25 17:38:24
【问题描述】:

我想在我的 jwt 令牌中有一个额外的声明说“mygroupsrmm”,我想在解码令牌后查看它。 我正在尝试向我的 jwt 令牌添加自定义声明,我将使用 Oauth2 流接收身份验证后。我已经修改了注册 AAD 应用程序的应用程序清单文件

“acceptMappedClaims”:真

& 遵循以下步骤:

//Step1 - 创建自定义策略

New-AzureADPolicy -Definition @('{"ClaimsMappingPolicy":{"Version":1,"IncludeBasicClaimSet":"true","ClaimsSchema":[{"Source":"user","ID":" extensionattribute2","SamlClaimType":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/rmmgname","JwtClaimType":"mygroupsrmm"}]} }') -DisplayName "MyGroupsRMMExtraClaims" -Type "ClaimsMappingPolicy"

//Step2 - 为我的 AAD 注册应用分配策略

$appID = $sp = Get-AzureADServicePrincipal -Filter "servicePrincipalNames/any(n: n eq '$appID')" $policyId = 添加-AzureADServicePrincipalPolicy -Id $sp.ObjectId -RefObjectId $policyId

以上两个步骤都成功了,现在我继续进行身份验证调用

//Step3 : GET /authorize API 调用

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?response_type=code&client_id=my-application-id-registered-in-AAD& redirect_uri=http://localhost:3000/callback&scope=openid%20profile%20email%20offline_access%20User.Read%20Files.Read

从这一步接收到授权码,然后将其传递给 /token API 调用

//Step4: POST /token 调用

POST https://login.microsoftonline.com/common/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&client_id=<<my-application-id-registered-in-AAD>>
&client_secret=<<client-secret-value-here>>
&code=<<code-received-from-step3>>
&redirect_uri=http://localhost:3000/callback

上述调用成功执行并返回access_token和id_token 但是发布解码令牌后,我无法查看我添加的自定义声明,即“mygroupsrmm”(通过jwt.io 查看解码令牌)

在从 Graph explorer 检查我的用户详细信息时,“extensionattribute2”为空,因此尝试使用此键字段更新值

//Step5:导航到Microsoft Graph Explorer并执行调用

/PATCH https://graph.microsoft.com/beta/me
body
{
    "onPremisesExtensionAttributes": {
        "extensionAttribute2": "myrmm-g2"
    }
}

以上调用抛出

"Forbidden - 403 - 492ms. 你需要同意 “修改权限(预览)”选项卡”

在查看“修改权限(预览)”时,所有必需的权限,即 User.ManageIdentities.All、User.ReadWrite.All、User.ReadWrite、Directory.ReadWrite.All、Directory.AccessAsUser.All 已被授予(同意)

//response
{
    "error": {
        "code": "Authorization_RequestDenied",
        "message": "Insufficient privileges to complete the operation.",
        "innerError": {
            "date": "2021-02-23T12:08:05",
            "request-id": "06ddd00b-db0f-4a7c-ae03-471763139939",
            "client-request-id": "c07843cf-89d4-10a7-89fa-f3b71445bc1f"
        }
    }
}

用于上述请求的授权令牌包含以下同意的权限/范围

"scp": "Directory.AccessAsUser.All Directory.Read.All Directory.ReadWrite.All OnlineMeetings.ReadWrite openid profile User.ManageIdentities.All User.Read User.Read.All User.ReadBasic.All User.ReadWrite User.ReadWrite.All email"

由于上述请求失败,我尝试修改另一个用户对象键值,即 jobTitle 以检查用户更新响应

/PATCH https://graph.microsoft.com/beta/me
{ "jobTitle" : "sr.mts"}

此调用也会引发 403 错误,代码为 Authorization_RequestDenied

我想知道为上述键设置值需要什么特定权限,即 jobTitle 或 extensionAttribute2 以查看解码的 jwt 令牌中的自定义声明键值。 任何形式的帮助将不胜感激。

【问题讨论】:

  • 您是管理员吗?
  • 不,我不是管理员,但我的管理员已同意所有必需的权限,即 User.ManageIdentities.All、User.ReadWrite.All、User.ReadWrite、Directory.ReadWrite。全部,Directory.AccessAsUser.All
  • 您必须是管理员才能修改此属性。我刚才已经测试过了。
  • 好的让管理员修改这个属性再检查一下
  • 好的,尝试授予您的用户全局管理员角色。

标签: azure azure-active-directory microsoft-graph-api azure-ad-graph-api


【解决方案1】:

您必须是管理员才能修改此属性。我刚才已经测试过了。

更新:Directory writer 角色分配给 AAD 用户后,上述问题已修复。 See here for success calls

【讨论】:

  • 嗨@Carl,谢谢你的回复,你能用这个{“onPremisesExtensionAttributes”检查一次吗:{“extensionAttribute2”:“myrmm-g2”}}
  • @AmritPalSingh 我尝试使用 {"onPremisesExtensionAttributes":{"extensionAttribute2":"myrmm-g2"}} 作为请求正文,它返回 400 给我。 i.stack.imgur.com/1rfBh.png。我不确定是否可以更改onPremisesExtensionAttributes 属性,因为我在Update user 的api 文档的请求正文中没有看到它。
  • @AmritPalSingh 您是否尝试授予用户管理员角色然后对其进行测试?结果如何?
  • 我尝试了同样的请求,但它返回了 405 (imgur.com/a/n6yJBSC)
  • @AmritPalSingh 这个很奇怪,我没有遇到这个错误,你的账号是工作账号还是学校账号?尝试使用其他 api 工具,例如 postman。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-15
  • 2021-02-12
  • 2013-01-22
  • 1970-01-01
相关资源
最近更新 更多