备注
In Azure Active Directory B2C, custom policies are designed primarily to address complex scenarios. For most scenarios, we recommend that you use built-in user flows. If you've not done so, learn about custom policy starter pack in Get started with custom policies in Active Directory B2C.
Azure Active Directory B2C(Azure AD B2C)为 OpenID Connect 协议标识提供者提供支持。 OpenID Connect 1.0 定义 OAuth 2.0 之上的标识层,并表示新式身份验证协议中的最先进的状态。 使用 OpenID Connect 技术配置文件,可以与基于 OpenID Connect 的标识提供者(如 Microsoft Entra ID)联合。 Federating with an identity provider allows users to sign in with their existing social or enterprise identities.
The Name attribute of the Protocol element needs to be set to OpenIdConnect
.
The InputClaims and InputClaimsTransformations elements are not required. 但你可能想要将其他参数发送到标识提供者。 The following example adds the domain_hint query string parameter with the value of contoso.com
to the authorization request.
<InputClaims>
<InputClaim ClaimTypeReferenceId="domain_hint" DefaultValue="contoso.com" />
</InputClaims>
OutputClaims 元素包含 OpenID Connect 标识提供者返回的声明列表。 You may need to map the name of the claim defined in your policy to the name defined in the identity provider. 还可以包含标识提供者未返回的声明,前提是设置了 DefaultValue
属性。
The OutputClaimsTransformations element may contain a collection of OutputClaimsTransformation elements that are used to modify the output claims or generate new ones.
The technical profile also returns claims that aren't returned by the identity provider:
- The identityProvider claim that contains the name of the identity provider.
- The authenticationSource claim with a default value of socialIdpAuthentication.
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="live.com" />
<OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication" />
<OutputClaim ClaimTypeReferenceId="issuerUserId" PartnerClaimType="sub" />
<OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="name" />
<OutputClaim ClaimTypeReferenceId="email" />
</OutputClaims>
特征 | 必选 | DESCRIPTION |
---|---|---|
客户编号 | 是的 | The application identifier of the identity provider. |
IdTokenAudience | 否 | The audience of the id_token. 如果指定,Azure AD B2C 会检查标识提供者返回的令牌中的 aud 声明是否等于 IdTokenAudience 元数据中指定的声明。 |
METADATA | 是的 | 指向 OpenID Connect 标识提供者配置文档的 URL,也称为 OpenID 已知配置终结点。 URL 可以包含 {tenant} 表达式,该表达式将替换为租户名称。 |
authorization_endpoint | 否 | 指向 OpenID Connect 标识提供者配置授权终结点的 URL。 authorization_endpoint元数据的值优先于 OpenID 已知配置终结点中指定的 authorization_endpoint 。 URL 可以包含 {tenant} 表达式,该表达式将替换为租户名称。 |
end_session_endpoint | 否 | 结束会话终结点的 URL。
end_session_endpoint 元数据的值优先于 OpenID 已知配置终结点中指定的 end_session_endpoint 。 |
发行人 | 否 | OpenID Connect 标识提供者的唯一标识符。 颁发者元数据的值优先于 OpenID 已知配置终结点中指定的 issuer 。 如果指定,Azure AD B2C 会检查标识提供者返回的令牌中的 iss 声明是否等于颁发者元数据中指定的声明。 |
供应商名称 | 否 | 标识提供者的名称。 |
response_types | 否 | 根据 OpenID Connect Core 1.0 规范的响应类型。 Possible values: id_token , code , or token . |
响应模式 | 否 | The method that the identity provider uses to send the result back to Azure AD B2C. Possible values: query , form_post (default), or fragment . |
范围 | 否 | 根据 OpenID Connect Core 1.0 规范定义的请求的范围。 Such as openid , profile , and email . |
HttpBinding | 否 | 与访问令牌和声明令牌终结点的预期 HTTP 绑定。 Possible values: GET or POST . |
ValidTokenIssuerPrefixes | 否 | 使用多租户标识提供者(如 Microsoft Entra ID)时,可用于登录到每个租户的密钥。 |
UsePolicyInRedirectUri | 否 | Indicates whether to use a policy when constructing the redirect URI. When you configure your application in the identity provider, you need to specify the redirect URI. The redirect URI points to Azure AD B2C, https://{your-tenant-name}.b2clogin.cn/{your-tenant-name}.partner.onmschina.cn/oauth2/authresp . If you specify true , you need to add a redirect URI for each policy you use. 例如: https://{your-tenant-name}.b2clogin.cn/{your-tenant-name}.partner.onmschina.cn/{policy-name}/oauth2/authresp 。 |
MarkAsFailureOnStatusCode5xx | 否 | 指示如果 HTTP 状态代码在 5xx 范围内,是否应将对外部服务的请求标记为失败。 默认值为 false 。 |
DiscoverMetadataByTokenIssuer | 否 | 指示是否应使用 JWT 中的颁发者发现 OIDC 元数据。如果需要基于颁发者生成元数据终结点 URL,请将此 URL 设置为 true 。 |
IncludeClaimResolvingInClaimsHandling | 否 | For input and output claims, specifies whether claims resolution is included in the technical profile. Possible values: true , or false (default). If you want to use a claims resolver in the technical profile, set this to true . |
token_endpoint_auth_method | 否 | Specifies how Azure AD B2C sends the authentication header to the token endpoint. Possible values: client_secret_post (default), and client_secret_basic , private_key_jwt . For more information, see OpenID Connect client authentication section. |
token_signing_algorithm | 否 | Specifies the signing algorithm to use when token_endpoint_auth_method is set to private_key_jwt . Possible values: RS256 (default) or RS512 . |
SingleLogoutEnabled | 否 | Indicates whether during sign-in the technical profile attempts to sign out from federated identity providers. For more information, see Azure AD B2C session sign-out. Possible values: true (default), or false . |
ReadBodyClaimsOnIdpRedirect | 否 | 设置为 true 从标识提供者重定向上的响应正文读取声明。 此元数据与 Apple ID 一起使用,其中声明在响应有效负载中返回。 |
<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">false</Item>
<Item Key="client_id">Your Microsoft application client ID</Item>
</Metadata>
以下设置可用于配置失败时显示的错误消息。 应在 OpenID Connect 技术配置文件中配置元数据。 可以将错误消息本地化。
特征 | 必选 | DESCRIPTION |
---|---|---|
UserMessageIfClaimsPrincipalDoesNotExist | 否 | 如果目录中未找到具有提供的用户名的帐户,则向用户显示的消息。 |
UserMessageIfInvalidPassword | 否 | 如果密码不正确,则向用户显示的消息。 |
UserMessageIfOldPasswordUsed | 否 | 如果使用旧密码,则向用户显示的消息。 |
The CryptographicKeys element contains the following attribute:
特征 | 必选 | DESCRIPTION |
---|---|---|
客户端密钥 | 是的 | The client secret of the identity provider application. 仅当 response_types 元数据设置为 code 且 token_endpoint_auth_method 设置为 client_secret_post 或 client_secret_basic 时,才需要此加密密钥。 In this case, Azure AD B2C makes another call to exchange the authorization code for an access token. 如果元数据设置为 id_token 可以省略加密密钥。 |
assertion_signing_key | 是的 | 用于对客户端断言进行签名的 RSA 私钥。 仅当 token_endpoint_auth_method 元数据设置为 private_key_jwt 时,才需要此加密密钥。 |
When you configure the redirect URI of your identity provider, enter https://{your-tenant-name}.b2clogin.cn/{your-tenant-name}.partner.onmschina.cn/oauth2/authresp
. 请确保将 {your-tenant-name}
替换为租户的名称。 The redirect URI needs to be in all lowercase.
例子:
- 使用 Microsoft Entra 帐户登录
- 允许用户使用自定义策略 登录到多租户Microsoft Entra 标识提供者