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

Sitecoreは、CE Connectを経由せず、Commerce Engineを直接呼び出すシステムに対してベアラートークン認証を使用します。呼び出し者はSitecoreの認証情報を使い、Sitecoreのアイデンティティサーバーに接続してトークンを取得しなければなりません。Sitecoreはリクエストヘッダーの認証ベアラーとしてそのトークンを使用します。

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

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

-   GetToken (http://{{SitecoreIdentityServerHost}}/connect/token)
    
    UIからログインせずにトークンを取得できるサイレントモード。Postman、Console、Deploymentスクリプトで使用。
    
-   Authorize (http://{{SitecoreIdentityServerHost}}/connect/authorize)
    
    Sitecore Identity Serverのログインページを読み込みます。ユーザーがSitecore認証情報で正常にログインすると、ユーザーは自分のウェブサイトに戻ります。Commerce Business Toolsで使用されます。
    

Commerce Engineを呼び出すシステムの識別(例:Postman、Commerce Business Tools)はSitecore.Commerce.IdentityServer.Host.xml設定ファイルに保存されなければなりません。XML設定ファイルのデフォルト位置はC:\\inetpub\\wwwroot\\<SXAStorefront-IdentityServer>\\Config\\production\\Sitecore.Commerce.IdentityServer.Host.xmlです。

以下は、Sitecore Identity ServerのSitecore.Commerce.IdentityServer.Host.xmlファイルにおけるPostmanクライアント構成のサンプルです。

<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>

以下は、Commerce 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>