我需要添加自定义声明“samAccountName”以显示在 token 中(使用 jwt)
首先,我创建了 powershell 脚本
New-AzureADPolicy -Definition @('{
"ClaimsMappingPolicy": {
"Version": 1,
"IncludeBasicClaimSet": "true",
"ClaimsSchema":[{
"Source": "user",
"ID": "onpremisessamaccountname",
"SamlClaimType": "samaccountname",
"JwtClaimType": "samAccountName"
},
]
}
}') -DisplayName "att_ext_samaccountname_even2_prod" -Type "ClaimsMappingPolicy"
在 azure list 中,我输入了“acceptMappedClaims”:true,它看起来像这样
但在“ token 配置 -> 可选声明”中,它看起来像这样(警告标志)
当选择“添加可选声明”时,我找不到要添加的声明
对我做错了什么或者缺少什么有什么想法吗?
提前致谢
最佳答案
我尝试在我的环境中重现相同的结果并得到以下结果:
我将 acceptedMappedClaims 修改为 true 并在应用 list 中添加了扩展程序,如下所示:
并得到与以下相同的错误:
或者,我使用下面的 PowerShell 命令在 token 中添加 samaccountname
扩展,如下所示:
$MyApp = (New-AzureADApplication -DisplayName "AppName").ObjectId
New-AzureADServicePrincipal -AppId (Get-AzureADApplication -SearchString "AppName").AppId
New-AzureADApplicationExtensionProperty -ObjectId $MyApp -Name "samaccountname" -DataType "String" -TargetObjects "User"
Set-AzureADUserExtension -ObjectId ServicePrincipalObjectId -ExtensionName "extension_XXXX_samaccountname" -ExtensionValue "Value"
执行上述命令后,我得到如下响应:
我能够将 samaccountname
添加为 Azure 门户中的可选声明,如下所示:
解码 token (使用授权代码生成)后,流程成功获得samaccountname
,如下所示:
欲了解更多详情,请引用以下链接:
Azure AD cmdlets to work with extension attributes | Microsoft Docs
Inlcude onpemise samaccount in azure ad claims by soumi-MSFT
关于azure - 将自定义声明 "samaccountname"添加到 Azure 广告中时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72980955/