AuthenticationTokenProvider class

Version: 10.3

To support authentication by using tokens in all of the Commerce Connect APIs, we have introduced an AuthenticationTokenProvider class. It consists of an interface defined in the Sitecore.Commerce.Config file and a default implementation that always returns NULL, meaning no token is provided.

The Sitecore.Commerce.config file defines the following authentication provider and AuthenticationToken entity configuration:

RequestResponse
<authenticationTokenProvider type="Sitecore.Commerce.Providers.AuthenticationTokenProvider, Sitecore.Commerce.Connect.Core" singleInstance="true"/>
<commerce.Entities>
<AuthenticationToken type="Sitecore.Commerce.Entities.AuthenticationToken, Sitecore.Commerce.Connect.Core" />
</commerce.Entities>
The IAuthenticationTokenProvider interface and AuthenticationTokenProvider class diagrams.

Name

Description

GetToken

Must return the token if one is required.

The introduction of the provider centralizes the logic of providing the Token. The ServiceProviderRequestbase class that is used in all service methods as an input parameter has been extended with an AuthenticationToken property. The property can be set explicitly on every call made through Commerce Connect. If the property is not set, the AuthenticationTokenProvider class is instantiated and called, and the return value is assigned to the property.

The AuthenticationToken is defined as a class that can be customized for extensibility purposes.

The following is an example of how to explicitly pass the authentication token into a service call:

RequestResponse
var request = new GetCustomerRequest(customerId);
var token = this.EntityFactory.Create<AuthenticationToken>("AuthenticationToken");
    
token.Token = "mytoken";
request.AuthenticationToken = token;
var result = this.CustomerServiceProvider.GetCustomer(request);           

Do you have some feedback for us?

If you have suggestions for improving this article,