使用 Azure Active Directory B2C 设置 eBay 帐户的注册和登录功能

重要

自 2025 年 5 月 1 日起,Azure AD B2C 将不再可供新客户购买。 在我们的常见问题解答中了解详细信息

在开始之前,请使用此页面顶部的 “选择策略类型 选择器”来选择要设置的策略类型。 Azure Active Directory B2C 提供了两种定义用户如何与应用程序交互的方法:通过预定义的用户流,或者通过可完全配置的自定义策略。 对于每种方法,本文中所需的步骤都不同。

此功能仅适用于自定义策略。 对于设置步骤,请在前面的选择器中选择“自定义策略”。

先决条件

创建 eBay 应用程序

若要在 Azure Active Directory B2C(Azure AD B2C)中为具有 eBay 帐户的用户启用登录,需要在 eBay 开发人员控制台中创建应用程序。 有关详细信息,请参阅 创建开发人员帐户。 如果还没有 eBay 开发人员帐户,请注册 https://developer.ebay.com/signin

若要创建 eBay 应用程序,请执行以下步骤:

  1. 使用您的 eBay 开发人员帐户凭据,登录 eBay 开发人员控制台内的 应用程序密钥
  2. 输入 应用程序标题
  3. “生产”下,选择“ 创建密钥集”。
  4. “确认此帐户的主要联系人 ”页中,提供帐户详细信息。 若要完成注册过程,请选择“ 继续创建密钥”。
  5. 复制 应用 ID(客户端 ID)应用 ID(客户端 ID)的值。 将标识提供者添加到租户时需要这两个值。
  6. 选择 “用户令牌”,然后选择 “通过应用程序从 eBay 获取令牌”。
  7. 选择 “添加 eBay 重定向 URL”。
    1. 输入 你的隐私策略 URL 的有效 URL,例如 https://www.contoso.com/privacy。 策略 URL 是继续提供应用程序的隐私信息的页面。
    2. 您的认证已被接受的 URL 中,输入 https://your-tenant-name.b2clogin.cn/your-tenant-name.partner.onmschina.cn/oauth2/authresp。 将 your-tenant-name 替换为租户的名称。
  8. 选择“保存”

创建策略密钥

需要存储以前在 Azure AD B2C 租户中记录的客户端密码。

  1. 登录到 Azure 门户
  2. 如果有权访问多个租户,请选择顶部菜单中的“设置”图标,从“目录 + 订阅”菜单切换到你的 Azure AD B2C 租户。
  3. 选择 Azure 门户左上角的“所有服务”,然后搜索并选择“Azure AD B2C” 。
  4. 在“概述”页上选择“标识体验框架”。
  5. 选择“策略密钥”,然后选择“添加”
  6. 对于“选项”,选择 Manual
  7. 输入策略密钥的名称。 例如,eBaySecret。 前缀 B2C_1A_ 会自动添加到密钥名称。
  8. “机密”中,输入之前记录的客户端密码。
  9. 在“密钥用法”处选择
  10. 选择 创建

将 eBay 配置为标识提供者

要使用户能够使用 eBay 帐户登录,需将该帐户定义为 Azure AD B2C 可通过终结点与之通信的声明提供程序。 该终结点将提供一组声明,Azure AD B2C 使用这些声明来验证特定的用户是否已完成身份验证。

通过将 eBay 帐户添加到策略扩展文件中的 ClaimsProviders 元素,可以将 eBay 帐户定义为声明提供程序。

  1. 打开 TrustFrameworkExtensions.xml

  2. 找到 ClaimsProviders 元素。 如果该元素不存在,请在根元素下添加它。

  3. 添加一个新的 ClaimsProvider,如下所示:

    <!--
    <ClaimsProviders> -->
      <ClaimsProvider>
        <Domain>ebay.com</Domain>
        <DisplayName>eBay</DisplayName>
        <TechnicalProfiles>
          <TechnicalProfile Id="eBay-OAUTH2">
            <DisplayName>eBay</DisplayName>
            <Protocol Name="OAuth2" />
            <Metadata>
              <Item Key="ProviderName">ebay.com</Item>
              <Item Key="authorization_endpoint">https://auth.ebay.com/oauth2/authorize</Item>
              <Item Key="AccessTokenEndpoint">https://api.ebay.com/identity/v1/oauth2/token</Item>
              <Item Key="ClaimsEndpoint">https://apiz.ebay.com/commerce/identity/v1/user/</Item>
              <Item Key="HttpBinding">POST</Item>
              <Item Key="BearerTokenTransmissionMethod">AuthorizationHeader</Item>
              <Item Key="token_endpoint_auth_method">client_secret_basic</Item>
              <Item Key="scope">https://api.ebay.com/oauth/api_scope/commerce.identity.readonly</Item>
              <Item Key="UsePolicyInRedirectUri">0</Item>
              <!-- Update the Client ID below to the Application ID -->
              <Item Key="client_id">Your eBay app ID</Item>
            </Metadata>
            <CryptographicKeys>
              <Key Id="client_secret" StorageReferenceId="eBaySecret"/>
            </CryptographicKeys>
            <OutputClaims>
              <OutputClaim ClaimTypeReferenceId="issuerUserId" PartnerClaimType="userId"/>
              <OutputClaim ClaimTypeReferenceId="givenName" PartnerClaimType="individualAccount.firstName"/>
              <OutputClaim ClaimTypeReferenceId="surname" PartnerClaimType="individualAccount.lastName"/>
              <OutputClaim ClaimTypeReferenceId="displayName" PartnerClaimType="username"/>
              <OutputClaim ClaimTypeReferenceId="email" PartnerClaimType="email"/>
              <OutputClaim ClaimTypeReferenceId="identityProvider" DefaultValue="ebay.com" AlwaysUseDefaultValue="true" />
              <OutputClaim ClaimTypeReferenceId="authenticationSource" DefaultValue="socialIdpAuthentication" AlwaysUseDefaultValue="true" />
            </OutputClaims>
            <OutputClaimsTransformations>
              <OutputClaimsTransformation ReferenceId="CreateRandomUPNUserName"/>
              <OutputClaimsTransformation ReferenceId="CreateUserPrincipalName"/>
              <OutputClaimsTransformation ReferenceId="CreateAlternativeSecurityId"/>
            </OutputClaimsTransformations>
            <UseTechnicalProfileForSessionManagement ReferenceId="SM-SocialLogin" />
          </TechnicalProfile>
        </TechnicalProfiles>
      </ClaimsProvider>
    <!--
    </ClaimsProviders> -->
    
  4. 将client_id设置为应用程序注册中的应用程序 ID。

  5. 保存文件。

添加用户旅程

此时,标识提供者已设置,但还不能在任何登录页中使用。 如果你没有自己的自定义用户旅程,请创建现有模板用户旅程的副本,否则,请继续执行下一步。

  1. 打开初学者包中的 TrustFrameworkBase.xml 文件。
  2. 找到并复制包含 Id="SignUpOrSignIn" 元素的完整内容。
  3. 打开 TrustFrameworkExtensions.xml 并找到 UserJourneys 元素。 如果该元素不存在,请添加一个。
  4. 将您复制的 UserJourney 元素的完整内容粘贴到 UserJourneys 元素下作为其子项。
  5. 对用户旅程的 ID 进行重命名。 例如,Id="CustomSignUpSignIn"

将标识提供者添加到用户旅程

现在你已拥有用户旅程,请将新的身份提供者添加到用户旅程中。 首先添加一个“登录”按钮,然后将该按钮链接到某个操作。 该操作是前面创建的技术配置文件。

  1. 在用户旅程中,查找包含 Type="CombinedSignInAndSignUp"Type="ClaimsProviderSelection" 的业务流程步骤元素。 通常这是第一个编排步骤。 ClaimsProviderSelections 元素包含用户可以用来登录的标识提供者列表。 元素的顺序将决定向用户显示的登录按钮的顺序。 添加ClaimsProviderSelection XML 元素。 将 TargetClaimsExchangeId 的值设置为易记名称。

  2. 在下一个编排步骤中,添加 ClaimsExchange 元素。 将 ID 设为目标声明交换 ID 的值。将 TechnicalProfileReferenceId 的值更新为先前创建的技术配置文件的 ID。

下面的 XML 演示了使用标识提供者进行用户旅程的前两个业务流程步骤:

<OrchestrationStep Order="1" Type="CombinedSignInAndSignUp" ContentDefinitionReferenceId="api.signuporsignin">
  <ClaimsProviderSelections>
    ...
    <ClaimsProviderSelection TargetClaimsExchangeId="eBayExchange" />
  </ClaimsProviderSelections>
  ...
</OrchestrationStep>

<OrchestrationStep Order="2" Type="ClaimsExchange">
  ...
  <ClaimsExchanges>
    <ClaimsExchange Id="eBayExchange" TechnicalProfileReferenceId="eBay-OAUTH2" />
  </ClaimsExchanges>
</OrchestrationStep>

配置信赖方策略

信赖方策略(例如 SignUpSignIn.xml)指定 Azure AD B2C 将执行的用户旅程。 在信赖方内查找 DefaultUserJourney 元素。 更新 ReferenceId,使其与已在其中添加标识提供者的用户旅程 ID 匹配

在以下示例中,对于 CustomSignUpSignIn 用户旅程,将 ReferenceId 设置为 CustomSignUpSignIn

<RelyingParty>
  <DefaultUserJourney ReferenceId="CustomSignUpSignIn" />
  ...
</RelyingParty>

上传自定义策略

  1. 登录到 Azure 门户
  2. 在门户工具栏中选择“目录 + 订阅”图标,然后选择包含 Azure AD B2C 租户的目录。
  3. 在 Azure 门户中,搜索并选择 Azure AD B2C
  4. 在“策略”下,选择“Identity Experience Framework”
  5. 选择“上传自定义策略”,然后上传已更改的两个策略文件,其顺序为:先上传扩展策略(例如 ),然后上传信赖方策略(例如 TrustFrameworkExtensions.xml)。

测试自定义策略

  1. 选择依赖方策略,例如 B2C_1A_signup_signin
  2. 对于应用程序,请选择您前面注册的 Web 应用程序。 “回复 URL”应显示为
  3. 选择“立即运行”按钮。
  4. 在注册或登录页中,选择 eBay 以使用 eBay 帐户登录。

如果登录过程成功,浏览器将重定向到 https://jwt.ms,后者显示 Azure AD B2C 返回的令牌内容。