ベアラー トークン認証

Current version: 10.1

Sitecore は、Commerce Engine を直接呼び出すすべてのシステムに対してベアラー トークン認証を使用します。呼び出し元は、Sitecore 資格情報を使用して Sitecore Identity Server に接続し、トークンを取得する必要があります。たとえば、Commerce Engine Connect などの既知のクライアントは、クライアント トークンを要求する必要があります。Sitecore は、要求ヘッダーで、これらの認証トークンを認証ベアラーとして使用します。

Sitecore Identity Server の URL は、Commerce Engine の config.json ファイルにある SitecoreIdentityServerUrl パラメーターで指定する必要があります。

Sitecore Identity Server は、トークンを取得するために次の 2 つのエンドポイントを提供します。

  • GetToken (http://{{SitecoreIdentityServerHost}}/connect/token)

    UI からログインせずにトークンを取得できるサイレント モード。これは、Postman、コンソール、およびデプロイ スクリプトで要求を認証するために使用されます。

  • Authorize (http://{{SitecoreIdentityServerHost}}/connect/authorize)

    Sitecore Identity のログイン ページをロードします。ユーザーが Sitecore 資格情報を使って正常にログインすると、自身の Web サイトに戻されます。たとえば、Sitecore XC Business Tools のユーザーがこの方法で認証されます。

Commerce Engine を呼び出すシステム (Postman、Commerce Business Tools、Commerce Engine Connect など) の ID は、Sitecore.Commerce.IdentityServer.Host.xml 設定ファイルに保存する必要があります。XML 設定ファイルのデフォルトの場所は、C:\inetpub\wwwroot\<SXAStorefront-IdentityServer>\Config\production\Sitecore.Commerce.IdentityServer.Host.xml です。

Postman クライアント認証の設定例

以下に、Postman クライアントに対応した Sitecore Identity Server の Sitecore.Commerce.IdentityServer.Host.xml ファイルにおけるデフォルトのクライアント設定例を示します。

RequestResponse
<PostmanClient>
    <ClientId>postman-api</ClientId>
    <ClientName>Postman API</ClientName>
    <AccessTokenType>0</AccessTokenType>
    <AllowOfflineAccess>true</AllowOfflineAccess>
    <AlwaysIncludeUserClaimsInIdToken>false</AlwaysIncludeUserClaimsInIdToken>
    <AccessTokenLifetimeInSeconds>3600</AccessTokenLifetimeInSeconds>
    <IdentityTokenLifetimeInSeconds>3600</IdentityTokenLifetimeInSeconds>
    <AllowAccessTokensViaBrowser>true</AllowAccessTokensViaBrowser>
    <RequireConsent>false</RequireConsent>
    <RequireClientSecret>false</RequireClientSecret>
    <AllowedGrantTypes>
      <AllowedGrantType1>password</AllowedGrantType1>
    </AllowedGrantTypes>
    <RedirectUris>
       <RedirectUri1>{AllowedCorsOrigin}/oauth2/callback</RedirectUri1>
    </RedirectUris>
    <PostLogoutRedirectUris>
       <PostLogoutRedirectUri1>{AllowedCorsOrigin}</PostLogoutRedirectUri1>
       </PostLogoutRedirectUris>
    <AllowedCorsOrigins>
        <AllowedCorsOrigins1>https://www.getpostman.com</AllowedCorsOrigins1>
     </AllowedCorsOrigins>
    <AllowedScopes>
        <AllowedScope1>openid</AllowedScope1>
        <AllowedScope2>EngineAPI</AllowedScope2>
        <AllowedScope3>postman_api</AllowedScope3>
        </AllowedScopes>
     <UpdateAccessTokenClaimsOnRefresh>true</UpdateAccessTokenClaimsOnRefresh>
 </PostmanClient>
    

Business Tools クライアント認証の設定例

以下に、Sitecore XC Business Tools に対応した Sitecore.Commerce.IdentityServer.Host.xml のクライアント設定例を示します。

RequestResponse
<Clients>
     <CommerceClient>
       <ClientId>CommerceBusinessTools</ClientId>
       <ClientName>CommerceBusinessTools</ClientName>
       <AccessTokenType>0</AccessTokenType>
       <AllowOfflineAccess>true</AllowOfflineAccess>
       <AlwaysIncludeUserClaimsInIdToken>false</AlwaysIncludeUserClaimsInIdToken>
       <AccessTokenLifetimeInSeconds>3600</AccessTokenLifetimeInSeconds>
       <IdentityTokenLifetimeInSeconds>3600</IdentityTokenLifetimeInSeconds>
       <AllowAccessTokensViaBrowser>true</AllowAccessTokensViaBrowser>
       <RequireConsent>false</RequireConsent>
       <RequireClientSecret>false</RequireClientSecret>
       <AllowedGrantTypes>
         <AllowedGrantType1>implicit</AllowedGrantType1>
       </AllowedGrantTypes>
       <RedirectUris>
         <RedirectUri1>{AllowedCorsOrigin}</RedirectUri1>
       </RedirectUris>
       <PostLogoutRedirectUris>
         <PostLogoutRedirectUri1>{AllowedCorsOrigin}</PostLogoutRedirectUri1>
       </PostLogoutRedirectUris>
       <AllowedCorsOrigins>                     <AllowedCorsOriginsGroup1>http://localhost:4200|https://localhost:4200|http://localhost:5005|https://localhost:5005</AllowedCorsOriginsGroup1>
       </AllowedCorsOrigins>
       <AllowedScopes>
         <AllowedScope1>openid</AllowedScope1>
         <AllowedScope2>dataEventRecords</AllowedScope2>
         <AllowedScope3>dataeventrecordsscope</AllowedScope3>
         <AllowedScope4>securedFiles</AllowedScope4>
         <AllowedScope5>securedfilesscope</AllowedScope5>
         <AllowedScope6>role</AllowedScope6>
         <AllowedScope7>EngineAPI</AllowedScope7>
       </AllowedScopes>
       <UpdateAccessTokenClaimsOnRefresh>true</UpdateAccessTokenClaimsOnRefresh>
     </CommerceClient>

Commerce Engine Connect クライアント認証の設定例

以下に、Commerce Engine Connect クライアントに対応した Sitecore.Commerce.IdentityServer.Host.xml におけるデフォルトのクライアント設定例を示します。

RequestResponse
<CommerceEngineConnectClient>
  <ClientId>CommerceEngineConnect</ClientId>
  <ClientName>CommerceEngineConnect</ClientName> 
  <AccessTokenType>0</AccessTokenType>
  <AllowOfflineAccess>true</AllowOfflineAccess>
<AlwaysIncludeUserClaimsInIdToken>false</AlwaysIncludeUserClaimsInIdToken>
  <AccessTokenLifetimeInSeconds>3600</AccessTokenLifetimeInSeconds>
  <IdentityTokenLifetimeInSeconds>3600</IdentityTokenLifetimeInSeconds>
  <AllowAccessTokensViaBrowser>true</AllowAccessTokensViaBrowser>
  <RequireConsent>false</RequireConsent>
  <RequireClientSecret>true</RequireClientSecret>
  <AllowedGrantTypes>
    <AllowedGrantType1>client_credentials</AllowedGrantType1>
  </AllowedGrantTypes>
  <RedirectUris>
    <RedirectUri1>{AllowedCorsOrigin}/oauth2/callback</RedirectUri1></RedirectUris>
  <PostLogoutRedirectUris>
    <PostLogoutRedirectUri1>{AllowedCorsOrigin}/PostLogoutRedirectUri1>
    </PostLogoutRedirectUris>
  <AllowedCorsOrigins>
    <AllowedCorsOriginsGroup1>HOSTNAME</AllowedCorsOriginsGroup1>
    </AllowedCorsOrigins>
  <AllowedScopes>
    <AllowedScope1>openid</AllowedScope1>
    <AllowedScope2>sitecore.profile</AllowedScope2>
    <AllowedScope3>sitecore.profile.api</AllowedScope3>
    <AllowedScope4>EngineAPI</AllowedScope4>
  </AllowedScopes>
<UpdateAccessTokenClaimsOnRefresh>true</UpdateAccessTokenClaimsOnRefresh>
  <ClientSecrets>
     <ClientSecret1>CLIENTSECRET</ClientSecret1>
  </ClientSecrets>
</CommerceEngineConnectClient

Do you have some feedback for us?

If you have suggestions for improving this article,