首页 文章

如何将属性从Azure AD登录映射到B2C标识?

提问于
浏览
0

按照此示例https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-aad-custom,我们已设法将Azure AD目录('AD')与Azure AD B2C目录('B2C')联合,因此我们可以对社交和自我声明注册公共应用程序,我们的工作用户也可以登录与他们的正常工作ID . 这很好用,为我们解决了一个复杂的场景 .

在使用B2C保护的应用程序中,我们需要向AD用户显示与其工作身份相关的内容(特别是我们需要根据他们的工作角色过滤产品),但这些信息对我们来说是不可用的,因为注册应用程序会为用户生成新的B2C身份(实际上是他们AD身份的代理) .

我们需要做的是将用户的原始AD身份映射到新的B2C身份 . AD用户的其他属性(如Given Name和Surname)已经映射,这似乎发生在我们的自定义策略的 ClaimsProvider 元素中,通过 PartnerClaimType 属性:

<OutputClaims>
    <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="oid"/>
    <OutputClaim ClaimTypeReferenceId="tenantId" PartnerClaimType="tid"/>
    <OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="given_name" />
    <OutputClaim ClaimTypeReferenceId="surName" PartnerClaimType="family_name" />
    <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
    <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="contosoAuthentication" />
    <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="AzureADContoso" />
</OutputClaims>

实际上,甚至看起来我们正在查找的ID可能会映射到属性( oid ) - 但是当我们稍后查询用户的B2C图时,不会返回此 oid 属性 .

那么 - 我们如何将用户的 Object ID 从工作AD目录映射到创建的新B2C标识上的属性?

1 回答

  • 3

    创建于11月28日

    当前,Azure AD用户(或任何外部用户)的对象标识符将保存到Azure AD B2C目录中的“alternativeSecurityId”属性,但无法通过Azure AD Graph API查询此内置属性 .

    但是,您可以创建自定义属性,并将Azure AD身份提供程序中的“oid”声明映射到与此自定义属性关联的自定义声明 .

    Azure Active Directory B2C: Creating and using custom attributes in a custom profile edit policy中描述了创建自定义属性并将其用作自定义声明 .

    对于您的特定情况,您应该:

    1:向基本策略添加 <ClaimType /> ,声明自定义声明:

    <ClaimType Id="extension_AzureADUserObjectId">
      <DisplayName>Azure AD User Object ID</DisplayName>
      <DataType>string</DataType>
    </ClaimType>
    

    2:在“SignInWithContoso”技术配置文件中映射“oid”声明:

    <OutputClaims>
      ...
      <OutputClaim ClaimTypeReferenceId="extension_AzureADUserObjectId" PartnerClaimType="oid" />
    </OutputClaims>
    

    3:将the extensions app的应用程序和对象标识符添加到"AAD-Common"技术配置文件中,该配置文件是将自定义声明读取和写入Azure AD B2C目录所需的:

    <TechnicalProfile Id="AAD-Common">
      <DisplayName>Azure Active Directory</DisplayName>
      <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.AzureActiveDirectoryProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
      <Metadata>
        <Item Key="ApplicationObjectId">Insert the object identifier for the b2c-extensions-app application here</Item>
        <Item Key="ClientId">Insert the application identifier for the b2c-extensions-app application here</Item>
      </Metadata>
      <CryptographicKeys>
        <Key Id="issuer_secret" StorageReferenceId="TokenSigningKeyContainer" />
      </CryptographicKeys>
      ...
    </TechnicalProfile>
    

    4:在“AAD-UserWriteUsingAlternativeSecurityId”技术配置文件中编写自定义声明:

    <PersistedClaims>
      ...
      <PersistedClaim ClaimTypeReferenceId="extension_AzureADUserObjectId" />
    </PersistedClaims>
    

    5:阅读“AAD-UserReadUsingAlternativeSecurityId”技术资料中的自定义声明:

    <OutputClaims>
      ...
      <OutputClaim ClaimTypeReferenceId="extension_AzureADUserObjectId" />
    </OutputClaims>
    

    6:在任何依赖方策略中发出自定义声明,或通过Azure AD Graph API进行查询 .

    更新于2月15日18日

    this announcement on 5 Feb 18开始,外部颁发者(即Azure AD租户)和外部用户标识符(即Azure AD用户的对象标识符)可以从Azure AD B2C目录中的用户对象的the "userIdentities" property中读取,其中"issuerUserId" property包含外部用户标识符的Base64编码:

    {
        "userIdentities": [
            {
                "issuer": "contoso.com",
                "issuerUserId": "Mjk2NzdlNTAtY2MwZS00MmU5LWJhNWMtZjFmMDdkZTUwMDhm"
            }
        ]
    }
    

相关问题