Authorization_RequestDenied 关于使用 Microsoft Graph 为用户密钥对象设置值

Authorization_RequestDenied on setting value for user key object using Microsoft Graph

我想在我的 jwt 令牌中有一个额外的声明说“mygroupsrmm”,我想查看 post 解码令牌。 我正在尝试向我的 jwt 令牌添加自定义声明,我将使用 Oauth2 流程接收 post 身份验证。我已经使用

修改了已注册 AAD 应用程序的应用程序清单文件

"acceptMappedClaims": true

& 遵循以下步骤:

//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 = <> Add-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 调用

//第四步:POST /令牌调用

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 但是 post 解码令牌我无法查看我添加的自定义声明,即“mygroupsrmm”(通过 jwt.io 查看解码令牌)

从 Graph 资源管理器检查我的用户详细信息时,“extensionattribute2”为空,因此尝试使用

更新此关键字段的值

//第 5 步:导航至 Microsoft Graph Explorer 并执行调用

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

以上调用抛出

"Forbidden - 403 - 492ms. You need to consent to the permissions on the Modify permissions (Preview) tab"

在查看“修改权限(预览版)”时,所有必需的权限,即 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"
        }
    }
}

用于上述请求的授权令牌包含以下同意 permissions/scopes

"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 令牌中查看自定义声明键值。 任何形式的帮助将不胜感激。

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

更新: Post 将 Directory writer 角色分配给 AAD 用户,上述问题已解决。 See here for success calls