多租户Azure AD在Azure AD B2C中的应用

6
我正在按照这里的答案进行操作:Multi-Tenant Azure AD Auth in Azure AD B2C with Custom Policies,以及这里的教程:https://github.com/Azure-Samples/active-directory-b2c-advanced-policies/blob/0129fc013ae5e66a3ee0046a5d0db2e8120d8f8e/Walkthroughs/IdP-AzureAD.md,但我无法登录,错误信息大致如下:
AADB2C: An exception has occured. Correlation ID: <GUID>. Timestamp: <Time>

此外,在最新的主版本中查看演示文稿时,整个页面已被删除,现在只包含指向https://learn.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-setup-aad-custom的链接,该链接并未显示如何为多租户Azure AD IDP配置ClaimsProvider。错误信息并不是非常有用,我感到有些迷失。我的技术概况如下:
<ClaimsProvider>
    <Domain>AzureAD</Domain>
    <DisplayName>Login using Azure AD</DisplayName>
    <TechnicalProfiles>
        <TechnicalProfile Id="AzureADProfile">
            <DisplayName>Azure AD</DisplayName>
            <Description>Login with your Azure AD account</Description>
            <Protocol Name="OpenIdConnect"/>
            <OutputTokenFormat>JWT</OutputTokenFormat>
            <Metadata>
                <Item Key="DiscoverMetadataByTokenIssuer">true</Item>
                <Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com/</Item>
                <Item Key="authorization_endpoint">https://login.windows.net/common/oauth2/v2.0/authorize</Item>
                <Item Key="client_id">MyAzureADB2CAppId</Item>
                <Item Key="IdTokenAudience">MyAzureADB2CAppId</Item>
                <Item Key="response_types">id_token</Item>
                <Item Key="UsePolicyInRedirectUri">false</Item>
                <Item Key="BearerTokenTransmissionMethod">AuthorizationHeader</Item>
                <Item Key="scope">openid</Item>
                <Item Key="HttpBinding">POST</Item>
            </Metadata>
            <CryptographicKeys>
                <Key Id="client_secret" StorageReferenceId="B2C_1A_B2CSecret"/>
            </CryptographicKeys>
            <OutputClaims>
                <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="oid"/>
                <OutputClaim ClaimTypeReferenceId="tenantId" PartnerClaimType="tid"/>
                <OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="unique_name" />
                <OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="given_name" />
                <OutputClaim ClaimTypeReferenceId="surName" PartnerClaimType="family_name" />
                <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
                <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="azureADAuthentication" />
                <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="AzureAD" />
            </OutputClaims>
            <OutputClaimsTransformations>
                <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/>
                <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName"/>
                <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId"/>
                <OutputClaimsTransformation ReferenceId="CreateSubjectClaimFromAlternativeSecurityId"/>
            </OutputClaimsTransformations>
            <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop"/>
        </TechnicalProfile>
    </TechnicalProfiles>
</ClaimsProvider>
编辑:根据spottedhahn的建议,我使用了用户旅程记录器,成功获取了真正的错误信息。
The response received from the ClaimsProvider using TechnicalProfile 
"<My_Azure_AD_Common_Profile>" in policy "<My_RP_Policy>" of tenant 
"<My_B2C_Tenant>" did not contain an "id_token".

问题是:连接多租户Azure AD到Azure AD B2C仍然受支持吗?如何配置使其工作?

使用user journey recorder可能提供比“发生异常”更多的细节信息。 - spottedmahn
@spottedmahn 我尝试使用b2crecorder.azurewebsites.net进行设置,但trace_102.html上没有日志出现。 - Harry Ninh
也许使用另一个线程来进行故障排除会更好。我以前用过,所以我知道它是有效的。我以前曾经搞砸过查看URL。 - spottedmahn
你看过这个指南了吗?https://learn.microsoft.com/zh-cn/azure/active-directory-b2c/active-directory-b2c-setup-aad-custom - spottedmahn
1
是的,我做到了。那里的指南是关于设置单租户Azure AD的,我成功地完成了。但是没有提到使用公共终结点的多租户,这正是我现在要实现的。 - Harry Ninh
显示剩余7条评论
1个回答

6

当将Azure AD B2C与Azure AD的公共端点联接时,可以与以下之一集成:

  • v1.0端点:https://login.microsoftonline.com/common/oauth2/authorize
  • v2.0端点:https://login.microsoftonline.com/common/oauth2/v2.0/authorize

v1.0端点

要将Azure AD B2C与v1.0端点集成,必须通过Azure门户注册Azure AD B2C,并使用您的Azure AD租户进行如下设置:

  1. 登录到Azure门户。
  2. 在顶部栏中,选择您的Azure AD目录。
  3. 在左侧边栏中,选择所有服务并找到“应用程序注册”。
  4. 选择新建应用程序注册
  5. 名称中,输入应用程序名称,例如"Azure AD B2C"。
  6. 应用程序类型中,选择Web应用程序/API
  7. 登陆URL中,输入https://login.microsoftonline.com/te/<tenant>/oauth2/authresp,其中替换<tenant>为您的Azure AD B2C租户名称(例如"contosob2c.onmicrosoft.com")。
  8. 选择创建
  9. 应用程序ID复制到后面使用。
  10. 选择设置,然后选择密钥
  11. 密码部分中,输入密码描述,选择密码持续时间,选择保存,然后将密码值复制到后面使用。

接着,必须通过Azure AD B2C门户使用第11步的应用程序秘密创建策略密钥(例如"AzureADClientSecret")。

然后,必须使用以下设置更新Azure AD技术配置文件:

<TechnicalProfile Id="AzureADAccountProfile">
  <DisplayName>Log in with your work account</DisplayName>
  <Protocol Name="OpenIdConnect"/>
  <OutputTokenFormat>JWT</OutputTokenFormat>
  <Metadata>
    <Item Key="authorization_endpoint">https://login.microsoftonline.com/common/oauth2/authorize</Item>
    <Item Key="client_id"><!-- Enter the application ID from step 9 --></Item>
    <Item Key="DiscoverMetadataByTokenIssuer">true</Item>
    <Item Key="HttpBinding">POST</Item>
    <Item Key="IdTokenAudience"><!-- Enter the application ID from step 9 --></Item>
    <Item Key="response_types">id_token</Item>
    <Item Key="scope">openid</Item>
    <Item Key="UsePolicyInRedirectUri">false</Item>
    <Item Key="ValidTokenIssuerPrefixes">https://sts.windows.net/</Item>
  </Metadata>
  <CryptographicKeys>
    <Key Id="client_secret" StorageReferenceId="B2C_1A_AzureADClientSecret"/>
  </CryptographicKeys>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="enterpriseAuthentication" />
    <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
    <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="tid" />
    <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="oid" />
    ...
  </OutputClaims>
  <OutputClaimsTransformations>
    <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/>
    <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName"/>
    <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId"/>
  </OutputClaimsTransformations>
  <UseTechnicalProfileForSessionManagement ReferenceId="ReferenceId="SM-Noop" />
</TechnicalProfile>

v2.0 endpoint

要将Azure AD B2C与v2.0端点集成,您必须通过应用程序注册门户网站在Azure AD租户中注册Azure AD B2C:

  1. 登录应用程序注册门户网站。
  2. 选择添加应用程序
  3. 应用程序名称中输入应用程序名称,例如“Azure AD B2C”,然后选择创建
  4. 复制应用程序 ID以备后用。
  5. 应用程序密码部分,选择生成新密码,并将密码值复制到后面使用。
  6. 平台部分中,选择添加平台,选择Web,然后输入一个重定向 URL,如https://login.microsoftonline.com/te/<tenant>/oauth2/authresp,其中你需要使用你的Azure AD B2C租户名称(例如“contosob2c.onmicrosoft.com”)替换<tenant>
  7. 在底部菜单中,选择保存

接下来,您必须通过Azure AD B2C门户网站创建策略密钥(例如“AzureADClientSecret”),其中包含步骤5中的应用程序密码。

然后,您必须使用以下设置更新Azure AD技术配置文件:

<TechnicalProfile Id="AzureADAccountProfile">
  <DisplayName>Log in with your work account</DisplayName>
  <Protocol Name="OpenIdConnect"/>
  <OutputTokenFormat>JWT</OutputTokenFormat>
  <Metadata>
    <Item Key="authorization_endpoint">https://login.microsoftonline.com/common/oauth2/v2.0/authorize</Item>
    <Item Key="client_id"><!-- Enter the application ID from step 4 --></Item>
    <Item Key="DiscoverMetadataByTokenIssuer">true</Item>
    <Item Key="HttpBinding">POST</Item>
    <Item Key="IdTokenAudience"><!-- Enter the application ID from step 4 --></Item>
    <Item Key="response_types">id_token</Item>
    <Item Key="scope">openid profile</Item>
    <Item Key="UsePolicyInRedirectUri">false</Item>
    <Item Key="ValidTokenIssuerPrefixes">https://login.microsoftonline.com/</Item>
  </Metadata>
  <CryptographicKeys>
    <Key Id="client_secret" StorageReferenceId="B2C_1A_AzureADClientSecret"/>
  </CryptographicKeys>
  <OutputClaims>
    <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="enterpriseAuthentication" />
    <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
    <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="tid" />
    <OutputClaim ClaimTypeReferenceId="socialIdpUserId" PartnerClaimType="oid" />
    ...
  </OutputClaims>
  <OutputClaimsTransformations>
    <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/>
    <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName"/>
    <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId"/>
  </OutputClaimsTransformations>
  <UseTechnicalProfileForSessionManagement ReferenceId="ReferenceId="SM-Noop" />
</TechnicalProfile>

1
嗨,Chris,我以前完成了v2.0的演练,但有一个小但重要的错误:我在“仅限Azure AD应用程序”下创建了应用程序,而我应该在“收敛应用程序”下创建。今天重新做了一遍,现在它可以工作了!所以如果你能编辑你的答案并为其他人提供这些详细信息,那就太好了。谢谢。 - Harry Ninh
嘿@ChrisPadgett,Azure门户现在在AD选项卡上有一个新的“应用程序注册(预览)”部分。(深度链接:https://portal.azure.com/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/RegisteredAppsPreview)。问题:我们是否仍然需要在App注册门户上注册应用程序,还是可以在此“预览”选项卡上完成?虽然屏幕指南似乎表明Azure门户预览选项卡UI现在是“推荐”的方式,但我没有看到在一个上注册的应用程序出现在另一个上的情况。 - user3624833
嗨,@SujaySarma。是的,您可以在Azure门户中使用应用程序注册(预览)功能,将Azure AD B2C与Azure AD进行注册。等我有一些时间后,我会补充上面的答案。谢谢! - Chris Padgett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接