1. 認証

ベアラートークン認証

Version:
日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

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

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

Sitecore Identityサーバーは、トークンを取得するために次の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サーバー Sitecore.Commerce.IdentityServer.Host.xmlファイルのデフォルトのクライアント設定の例を示しています。

<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にあるクライアント設定の例を示しています。

<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のデフォルトのクライアント設定の例を示します。

<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
この記事を改善するための提案がある場合は、 お知らせください!