Bearer token authentication

Current version: 9.0

Sitecore uses bearer token authentication for systems calling the Commerce Engine directly, without going through CE Connect. The caller must connect to the Sitecore Identity Server, using Sitecore credentials, to obtain a token. Sitecore uses that token as an authorization bearer in request headers.

You must specify the URL of the Sitecore Identity Server in the Commerce Engine's config.json file, in the SitecoreIdentityServerUrl parameter.

The Sitecore Identity Server provides the following two endpoints for obtaining a token:

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

    A silent mode that allows you to get a token without having to log in through the UI. Used by Postman, Console, and Deployment scripts.

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

    Loads the Sitecore Identity Server login page. Once the user logs in successfully with Sitecore credentials, the user is returned to their website. Used by the Commerce Business Tools.

The identity of any system calling the Commerce Engine (for example, Postman, Commerce Business Tools) must be stored in the Sitecore Identity Server’s configuration file.

The following is a sample of the client configuration in the Sitecore Identity Server’s appSettings.json file for the Postman client:

RequestResponse

"Clients": [
      {
        "ClientId": "postman-api",
        "ClientName": "Postman API",
        "AccessTokenType": 0,     
        "AccessTokenLifetimeInSeconds": 3600,     
        "IdentityTokenLifetimeInSeconds": 3600,     
        "AllowAccessTokensViaBrowser": true,
        "RequireConsent": false,
        "RequireClientSecret": false,
        "AllowedGrantTypes": [
          "password"
        ],
        "RedirectUris": [       
          "https://www.getpostman.com/oauth2/callback"
        ],
        "PostLogoutRedirectUris": [
          "https://www.getpostman.com"
        ],
        "AllowedCorsOrigins":
          "https://www.getpostman.com"
        ],
        "AllowedScopes": [
          "openid",
          "dataEventRecords",
          "dataeventrecordsscope",
          "securedFiles",
          "securedfilesscope",
          "role",
          "EngineAPI",
          "postman_api"

        ]

      }

    ]

The following is a sample of the client configuration in the Sitecore Identity Server’s appSettings.json file for the Commerce Business Tools:

RequestResponse
"Clients": [
      {
        "ClientId": "CommerceBusinessTools",
        "ClientName": "CommerceBusinessTools",
        "AccessTokenType": 0,      
        "AccessTokenLifetimeInSeconds": 3600,      
        "IdentityTokenLifetimeInSeconds": 3600,
        "AllowAccessTokensViaBrowser": true,
        "RequireConsent": false,
        "RequireClientSecret": false,
        "AllowedGrantTypes": [
          "implicit"
        ],
        "RedirectUris": [
          "http://localhost:4200",
          "http://localhost:4200/?"
        ],      
        "PostLogoutRedirectUris": [
          "http://localhost:4200",
          "http://localhost:4200/?"
        ],
        "AllowedCorsOrigins": [
          "http://localhost:4200/",
          "http://localhost:4200"
        ],
        "AllowedScopes": [
          "openid",
          "dataEventRecords",
          "dataeventrecordsscope",
          "securedFiles",
          "securedfilesscope",
          "role",
          "EngineAPI"
        ]

Do you have some feedback for us?

If you have suggestions for improving this article,