无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

huangapple go评论133阅读模式
英文:

Cannot find type [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] Error

问题

我尝试为我在租户中创建的应用程序注册添加额外的声明映射。

$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
New-Object : 无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy]请验证包含此类型的程序集是否已加载
At line:1 char:11
+ $policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMap ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [New-Object], PSArgumentException
    + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

我尝试重新安装 AzureAD 模块,并尝试安装 AzureADPreivew 模块,但没有帮助。感谢在这里提供帮助。

英文:

Im trying to add additional claim mapping to an app registration, Ive created in my tenant.

$app = Get-AzureADApplication -ObjectId &lt;obj-id&gt;
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy

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

Im getting the following error when I run this on line 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

I tried to re-install AzureAD module and also tried with installing AzureADPreivew Module also. But it was not helping. Appreciate help here.

答案1

得分: 1

以下是您要求的翻译部分:

I tried to reproduce the same in my environment and got below results:

When I ran same PowerShell script as you, I got same error like below:

$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")
)

Response:

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Alternatively, you can make use of New-AzureADPolicy command that requires AzureADPreview module.

To install that module, you need to uninstall AzureAD module like below:

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

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Now run below Powershell command to create claim mapping policy:

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"

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Note the ID of the policy from above response and assign it to your service principal using below command:

Add-AzureADServicePrincipalPolicy -Id serviceprincipal_ObjectID -RefObjectId policy_ID

To confirm whether the policy is assigned or not, you can run below command:

Get-AzureADServicePrincipalPolicy -Id serviceprincipal_ObjectID

Response:

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

I assigned value to above claim by running this Graph query:

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

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Make sure to set "acceptMappedClaims": true in App's Manifest like below:

Go to Azure Portal -> Azure Active Directory -> App registrations -> Your App -> Manifest

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Now, I generated token for above application and got claim successfully after decoding it in jwt.ms website like below:

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

英文:

I tried to reproduce the same in my environment and got below results:

When I ran same PowerShell script as you, I got same error like below:

$app = Get-AzureADApplication -ObjectId &lt;obj-id&gt;
$policy = New-Object Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy

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

Response:

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Alternatively, you can make use of New-AzureADPolicy command that requires AzureADPreview module.

To install that module, you need to uninstall AzureAD module like below:

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

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Now run below Powershell command to create claim mapping policy:

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

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Note the ID of the policy from above response and assign it to your service principal using below command:

Add-AzureADServicePrincipalPolicy -Id serviceprincipal_ObjectID -RefObjectId policy_ID

To confirm whether the policy is assigned or not, you can run below command:

Get-AzureADServicePrincipalPolicy -Id serviceprincipal_ObjectID

Response:

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

I assigned value to above claim by running this Graph query:

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

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Make sure to set &quot;acceptMappedClaims&quot;: true in App's Manifest like below:

Go to Azure Portal -> Azure Active Directory -> App registrations -> Your App -> Manifest

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

Now, I generated token for above application and got claim successfully after decoding it in jwt.ms website like below:

无法找到类型 [Microsoft.Open.AzureAD.Model.ClaimsMappingPolicy] 错误。

huangapple
  • 本文由 发表于 2023年3月8日 17:47:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/75671482.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定