Skip to main content

Authentication

An HTTP header is required to pass the authentication when performing the API request. The authentication requires a token to be used in the Authorization header of the HTTP request.

Authentication Token is a string sequence in the following format: "ASC pkey:datetime:hash", where

  • pkey - random string,
  • datetime - current UTC date and time in the "yyyyMMddHHmmss" format,
  • hash - hash value for the string in the "datetime\npkey" format.

The hash value is calculated using the HMAC-SHA1 function with the key from the core.machinekey value of the Hosted Solution site appSettings configuration.

Please note, that the token is valid for 5 minutes only, starting with the datetime.

Authentication Token example will look like this: "ASC abc:20100707140603:E7lwEXOplYS-0lbnV1XQnDSbi3w"

Generating token examples

public string CreateAuthToken(string pkey, string machinekey)
{
using (var hasher = new System.Security.Cryptography.HMACSHA1(System.Text.Encoding.UTF8.GetBytes(machinekey)))
{
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
var hash = System.Web.HttpServerUtility.UrlTokenEncode(hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(string.Join("\n", now, pkey))));

return string.Format("ASC {0}:{1}:{2}", pkey, now, hash);
}
}