Azure AD B2C中的多租户Azure AD

Har*_*inh 5 azure-ad-b2c

我在这里关注答案:具有自定义策略的Azure AD B2C中的多租户Azure AD身份验证

以及这里的演练: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>
Run Code Online (Sandbox Code Playgroud)

此外,在最新版母版中查看演练时,整个页面已被删除,现在仅包含指向https://docs.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>
Run Code Online (Sandbox Code Playgroud)

编辑:根据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".
Run Code Online (Sandbox Code Playgroud)

问题是:仍支持将多租户Azure AD链接到Azure AD B2C,如何配置才能使它正常工作?

Chr*_*ett 5

将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租户注册Azure AD B2C :

  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. 在“ 密码”部分中,输入密码说明,选择密码持续时间,选择“ 保存”,然后复制密码值以备后用。

然后,您必须使用步骤11中的应用程序密钥通过Azure AD B2C门户创建策略密钥(例如“ 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>
Run Code Online (Sandbox Code Playgroud)

v2.0端点

要将Azure AD B2C与v2.0终结点集成,必须通过Application Registration门户向Azure AD租户注册Azure AD B2C :

  1. 登录到应用程序注册门户。
  2. 选择添加应用
  3. 在“ 应用程序名称”中,输入应用程序名称,例如“ Azure AD B2C”,然后选择“ 创建”
  4. 复制应用程序ID以供以后使用。
  5. 在“ 应用程序密码部分中,选择“ 生成新密码”,然后复制密码值以供以后使用。
  6. 在“ 平台”部分中,选择“ 添加平台”,再选择“ Web”,然后输入“ Redirect URL as” https://login.microsoftonline.com/te/<tenant>/oauth2/authresp,在其中替换<tenant>为Azure AD B2C租户的名称(例如“ contosob2c.onmicrosoft.com”)。
  7. 在底部栏中,选择保存

然后,您必须使用步骤5中的应用程序密钥通过Azure AD B2C门户创建策略密钥(例如“ 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/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>
Run Code Online (Sandbox Code Playgroud)