---
title: "ベアラートークン認証"
slug: "bearer-token-authentication"
abstract: ""
---
# ベアラートークン認証

SitecoreはCommerce Engineを直接呼び出すすべてのシステムに対してベアラートークン認証を使用します。呼び出し者は[Sitecore](https://doc.sitecore.com/xp/en/developers/100/sitecore-experience-manager/en/sitecore-identity-server-authentication.html)の認証情報を使い、Sitecore Identityサーバーに接続してトークンを取得しなければなりません。例えば、Commerce Engine Connectのような既知のクライアントはクライアントトークンを要求しなければなりません。Sitecoreはリクエストヘッダーの認証ベアラーとしてこれらの認証トークンを使用します。

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

Sitecore Identityサーバーは、トークン取得のための以下の2つのエンドポイントを提供します:

-   GetToken (http://{{SitecoreIdentityServerHost}}/connect/token)
    
    UIからログインせずにトークンを取得できるサイレントモードです。これはPostman、コンソール、デプロイスクリプトでリクエストを認証するために使われます。
    
-   Authorize (http://{{SitecoreIdentityServerHost}}/connect/authorize)
    
    Sitecore Identityのログインページを読み込みます。ユーザーがSitecore認証情報でログインすると、ユーザーは元のウェブサイトに戻されます。例えば、Sitecore XC Business Toolsユーザーの認証方法はこれです。
    

Commerce Engineを呼び出すシステム(例:Postman、Commerce Business Tools、またはCommerce Engine Connect)の識別名は、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