【问题标题】:Differently-formatted issuerUserId when using Microsoft Account provider in Azure AD B2C在 Azure AD B2C 中使用 Microsoft 帐户提供程序时格式不同的 issuerUserId
【发布时间】:2018-11-22 10:02:35
【问题描述】:

我们正在调查将现有身份验证系统迁移到 Azure AD B2C。我们当前的系统接受 MSA 和 Google 登录,并且我们使用基于 IdentityServer 的内部开发服务,该服务将来自第三方 IdP 的 ID 存储在 Azure 表存储中。

我已按照setting up MSA as an ID providermigrating users with a social account 的说明进行操作,并在将现有 MSA ID 作为 userIdentities 发布到 AD Graph API 时将其转换为 base64(与上面第二个链接中的示例代码一致)。但是,当我使用 MSA 登录时,它不会识别我的帐户,而是将我定向到注册页面(作为我定义的登录/注册政策的一部分)。

如果我继续创建用户,然后在 Graph API 中使用 /users/<new-user-id> 端点检查新创建的用户,与我目前为 Microsoft 用户存储的内容相比,我会返回一个看起来很奇怪的 issuerUserId .

我现有用户的 ID 类似于 1234ab56789cde01,通过 B2C 发送给我的 ID 在 base64 解码时被格式化为 AAAAAAAAAAAAAAAAAAAAAAbCdEF12GhIj_KlM34nOPQ。 (更改值以避免任何潜在的隐私问题。)大写的“A”总是在开头,与只有一系列十六进制的原始 ID 相比,我从新格式的所有字母数字值中获取字符字符。

我已经设法让 Google 帐户正常工作。只需将它们转换为base64,它们就可以工作了。但我正在努力弄清楚如何迁移 MSA。要么我在应用程序注册方面做错了,要么还有另一个步骤来生成我刚刚丢失的AAAAAAAA-prefixed ID。任何帮助表示赞赏。谢谢!

【问题讨论】:

  • Azure AD B2C 正在将针对 Microsoft 帐户发出的 subject 声明保存到 userIdentity 对象。您是否引用了相同的声明?此外,我相信 subject 声明是成对标识符,即它对于特定应用程序是唯一的。
  • 我担心这是一个特定于应用程序的 ID,因为这意味着迁移不会像我希望的那样顺利。我们目前正在使用Microsoft.Owin.Security.MicrosoftAccount package 来提取 ID。我从中获得的子声明似乎与我在特定应用程序的客户端 ID/秘密范围之外查询 MS Graph API 时获得的 ID 相匹配。在阅读了 v2 端点的文档后,看来我这次真正想要的是 oid 而不是 sub 声明。

标签: azure azure-ad-b2c


【解决方案1】:

Microsoft 帐户的内置身份提供程序将 Microsoft 帐户的 sub(主题)声明映射到 userIdentityissuerUserId 属性强>对象。

如果您要迁移从 Microsoft 帐户的不同声明(例如 oid(对象标识符)声明)映射的身份,则必须先use custom policies,然后再进行@987654322 @ 进行以下修改:

<ClaimsProvider>
    <Domain>live.com</Domain>
    <DisplayName>Microsoft Account</DisplayName>
    <TechnicalProfiles>
        <TechnicalProfile Id="MSA-OIDC">
            <DisplayName>Microsoft Account</DisplayName>
            <Protocol Name="OpenIdConnect" />
            <Metadata>
                <Item Key="ProviderName">https://login.live.com</Item>
                <Item Key="METADATA">https://login.live.com/.well-known/openid-configuration</Item>
                <Item Key="response_types">code</Item>
                <Item Key="response_mode">form_post</Item>
                <Item Key="scope">openid profile email</Item>
                <Item Key="HttpBinding">POST</Item>
                <Item Key="UsePolicyInRedirectUri">0</Item>
                <Item Key="client_id">Your Microsoft application client id</Item>
            </Metadata>
            <CryptographicKeys>
                <Key Id="client_secret" StorageReferenceId="B2C_1A_MSASecret" />
            </CryptographicKeys>
            <OutputClaims>
                <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="live.com" />
                <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication" />
                <!-- ORIGINAL: The following output claims maps from the "sub" claim to the "issuerUserId" property. -->
                <!--<OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="sub" />-->
                <!-- MODIFICATION: The following output claims maps from the "oid" claim to the "issuerUserId" property. -->
                <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="oid" />
                <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
                <OutputClaim ClaimTypeReferenceId="email" />
            </OutputClaims>
            <OutputClaimsTransformations>
                <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName" />
                <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName" />
                <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId" />
                <OutputClaimsTransformation ReferenceId="CreateSubjectClaimFromAlternativeSecurityId" />
            </OutputClaimsTransformations>
            <UseTechnicalProfileForSessionManagement ReferenceId="SM-SocialLogin" />
        </TechnicalProfile>
    </TechnicalProfiles>
</ClaimsProvider>

有关开始使用自定义策略的信息,请参阅Azure Active Directory B2C: Get started with custom policies

【讨论】:

  • 明白了。非常感谢!我什至没有考虑为内置提供程序之一使用自定义策略。我现在看到的唯一问题是 id 是以 guid 格式出现的(我们现有的似乎不是完整的 guid),但这很容易通过在迁移中应用一些格式来克服。再次感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-10
  • 1970-01-01
  • 2019-01-06
  • 1970-01-01
  • 2021-09-18
  • 2018-01-12
  • 1970-01-01
相关资源
最近更新 更多