powershell 找不到类型[Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy]错误

68de4m5k  于 2023-03-30  发布在  Shell
关注(0)|答案(1)|浏览(143)

我试图添加额外的索赔Map到一个应用程序注册,我在我的租户创建。

$app = Get-AzureADApplication -ObjectId <obj-id>
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy

$policy.InputClaims = @(
    (New-Object Microsoft.Open.AzureAD.Model.InputClaim).Type("email")
)
$policy.OutputClaims = @(
    (New-Object Microsoft.Open.AzureAD.Model.OutputClaim).Type("t24user")
)
$policy.ClaimMappings = @(
    (New-Object Microsoft.Open.AzureAD.Model.ClaimMapping).InputClaimType("email").OutputClaimType("t24user").TransformationMethod("ExtractPrefixFromEmail")
)

当我在第2行运行这个命令时,我得到以下错误
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy

At line:1 char:11
+ $policy = New-Object -TypeName Microsoft.Open.AzureAD.Model.ClaimsMap ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

我尝试重新安装AzureAD模块,也尝试安装AzureADPreivew模块。但没有帮助。请在此提供帮助。

py49o6xq

py49o6xq1#

我尝试在我的环境中重现相同的结果,结果如下:

当我运行与您相同的PowerShell脚本时,我得到了相同的错误,如下所示:

$app = Get-AzureADApplication -ObjectId <obj-id>
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy

$policy.InputClaims = @(
    (New-Object Microsoft.Open.AzureAD.Model.InputClaim).Type("email")
)
$policy.OutputClaims = @(
    (New-Object Microsoft.Open.AzureAD.Model.OutputClaim).Type("t24user")
)
$policy.ClaimMappings = @(
    (New-Object Microsoft.Open.AzureAD.Model.ClaimMapping).InputClaimType("email").OutputClaimType("t24user").TransformationMethod("ExtractPrefixFromEmail")
)

答复:

也可以使用需要AzureADPreview模块的New-AzureADPolicy命令。
要安装该模块,您需要卸载AzureAD模块,如下所示:

Disconnect-AzureAD
Uninstall-Module AzureAD
Install-Module AzureADPreview
Connect-AzureAD

现在运行下面的PowerShell命令来创建声明Map策略:

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

注意上面响应中策略的**ID**,并使用以下命令将其分配给您的服务主体:

Add-AzureADServicePrincipalPolicy -Id serviceprincipal_ObjectID -RefObjectId policy_ID

确认是否分配策略,可以运行以下命令:

Get-AzureADServicePrincipalPolicy -Id serviceprincipal_ObjectID

答复:

我通过运行以下Graph查询将value分配给上述声明:

PATCH https://graph.microsoft.com/v1.0/me
{
"onPremisesExtensionAttributes": 
    {
        "extensionAttribute1": "sri_mail"
    }
}

请确保在App的Manifest中设置**"acceptMappedClaims": true**,如下所示:

转到Azure门户-〉Azure Active Directory -〉应用注册-〉您的应用-〉清单

现在,我为上面的应用生成了token,并在jwt.ms网站中解码成功领取,如下所示:

相关问题