Share via


使用 Azure Active Directory B2C 設定使用 eBay 帳戶註冊和登入

開始之前,請使用 [選擇原則類型 選取器] 來選擇您要設定的原則類型。 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. 複製應用程式識別碼 (用戶端識別碼)應用程式識別碼 (用戶端識別子) 的值。 您必須同時將識別提供者新增至租使用者。
  6. 選取 [使用者令牌],然後選取 [透過您的應用程式從 eBay 取得令牌]。
  7. 選取 [ 新增 eBay 重新導向 URL]。
    1. 輸入您隱私策略 URL 的有效 URL, 例如 https://www.contoso.com/privacy。 原則 URL 是您維護的頁面,可為您的應用程式提供隱私權資訊。
    2. 在 [ 您的驗證已接受 URL] 中, 輸入 https://your-tenant-name.b2clogin.com/your-tenant-name.onmicrosoft.com/oauth2/authresp。 如果您使用 自訂網域,請輸入 https://your-domain-name/your-tenant-name.onmicrosoft.com/oauth2/authresp。 取代為您的租使用者名稱,並以your-domain-name您的自訂網域取代 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. 針對 [ 金鑰使用方式],選取 Signature
  10. 選取建立

將 eBay 設定為識別提供者

若要讓使用者使用 eBay 帳戶登入,您必須將帳戶定義為 Azure AD B2C 可以透過端點進行通訊的宣告提供者。 端點提供一組宣告,供 Azure AD B2C 用來驗證特定使用者已驗證。

您可以將 eBay 帳戶新增至 原則擴充檔案中的 ClaimsProviders 元素,將它定義為宣告提供者。

  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設定為應用程式註冊中的應用程式識別碼。

  5. 儲存檔案。

新增使用者旅程圖

此時,識別提供者已設定,但尚未在任何登入頁面中提供。 如果您沒有自己的自定義使用者旅程圖,請建立現有範本使用者旅程圖的重複項目,否則請繼續進行下一個步驟。

  1. 從入門套件開啟 TrustFrameworkBase.xml 檔案。
  2. 尋找並複製包含 Id="SignUpOrSignIn"之 UserJourney 元素的整個內容
  3. 開啟 TrustFrameworkExtensions.xml 並尋找 UserJourneys 元素。 如果專案不存在,請新增一個。
  4. 貼上您複製為 UserJourneys 元素子系之 UserJourney 元素整個內容。
  5. 重新命名使用者旅程圖的標識碼。 例如: Id="CustomSignUpSignIn"

將識別提供者新增至使用者旅程圖

現在您已擁有使用者旅程圖,請將新的識別提供者新增至使用者旅程圖。 您必須先新增登入按鈕,然後將按鈕連結至動作。 動作是您稍早建立的技術配置檔。

  1. 尋找在 Type="CombinedSignInAndSignUp"使用者旅程圖中包含 或 Type="ClaimsProviderSelection" 的協調流程步驟元素。 通常是第一個協調流程步驟。 ClaimsProviderSelections 元素包含使用者可以登入的識別提供者清單。 元素的順序會控制向用戶呈現的登入按鈕順序。 新增 ClaimsProviderSelection XML 元素。 將 TargetClaimsExchangeId 的值設定為易記名稱。

  2. 在下一個 協調流程步驟中,新增 ClaimsExchange 元素。 將標識符設定為目標宣告交換標識碼的值。將TechnicalProfileReferenceId的值更新為您稍早建立之技術配置檔的標識碼。

下列 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 以符合您新增識別提供者的使用者旅程圖標識碼。

在下列範例中 CustomSignUpSignIn ,針對使用者旅程圖, ReferenceId 會設定為 CustomSignUpSignIn

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

上傳自定義原則

  1. 登入 Azure 入口網站
  2. 在入口網站工具列中選取 [ 目錄 + 訂 用帳戶] 圖示,然後選取包含 Azure AD B2C 租使用者的目錄。
  3. 在 Azure 入口網站中,搜尋並選取 [Azure AD B2C]
  4. 在 [原則] 底下,選取 [身分識別體驗架構]。
  5. 選取 [ 上傳自定義原則],然後上傳您變更的兩個原則檔案,順序如下:擴充原則,例如 TrustFrameworkExtensions.xml,然後是信賴憑證者原則,例如 SignUpSignIn.xml

測試您的自定義原則

  1. 選取您的信賴憑證者原則,例如 B2C_1A_signup_signin
  2. 針對 [ 應用程式],選取您 先前註冊的 Web 應用程式。 回覆 URL 應該會顯示 https://jwt.ms
  3. 選取 [ 立即 執行] 按鈕。
  4. 從 [註冊或登入] 頁面中,選取 [eBay] 以使用 eBay 帳戶登入。

如果登入程式成功,您的瀏覽器會重新導向至 https://jwt.ms,以顯示 Azure AD B2C 所傳回令牌的內容。

下一步

瞭解如何將 Facebook 令牌傳遞至您的應用程式