# Obtain an authentication token (C#)

Abstract

How to use the GetToken request using C# programming.

Bearer token authentication is used for systems calling the Commerce Engine directly, without going through Sitecore Commerce Engine Connect. To execute any operation in the Sitecore Experience Commerce (XC) system, the calling system must first connect to the Sitecore Identity Server to obtain an authentication token and include it in every call it makes to the Commerce Engine. Other operations can re-use the same token for as long as the token is valid.

The following shows an example of a GetToken request using C#:

public static class SitecoreIdServerAuth
{
{
using (var client = new HttpClient())
{
var content = new FormUrlEncodedContent(new []
{
new KeyValuePair<string, string>("client_id", "postman-api"),
new KeyValuePair<string, string>("scope", "openid EngineAPI postman_api"),
});
var response = await client.PostAsync("connect/token",content);