Skip to main content

Authentication & Authorization

Every request to the Checkout and Payment Admin API must be authenticated. This is done by passing the following HTTP headers to the API:

Timestamp

The timestamp should be the time in UTC when the message was sent. Use the format ”yyyy-MM-dd HH:mm:ss”.

Example: 2017-10-23 13:03:03

Authorization

This should be in the format “Svea {token}” where token is calculated using this formula:

base64(utf8({𝑐ℎ𝑒𝑐𝑘𝑜𝑢𝑡𝑚𝑒𝑟𝑐ℎ𝑎𝑛𝑡𝑖𝑑}:base64(lowercase(sha512(utf8({requestBody}{checkoutSecret}{timestamp}))))))

where:

  • {checkoutmerchantid} is the merchant identifier assigned to you by Svea.
  • {requestbody} is the body of the request (or an empty string for GET requests).
  • {checkoutsecret} is the secret key assigned to your CheckoutMerchantId by Svea.
  • {timestamp} is the same value as the timestamp header.
Example
Svea MTAwMDAxOjJEOEQ2QkQzRjNGMjYyRUM1NDcwRjhBNjUxRDk2NTIzRTI2M0NFNjEyQUI5MDkxREQzRUM1NkJBOURFRTMyNTUwNEUzM0FDOTM0NjhBMTlCREZDNjEwQjQ3QzE2RTQwMzk1MjIzMDE2QzQyRkFBN0UwNTFCQTAwQzg5RTcwRUEy

Token Generation Example Code

Token Generation Example
public class Authentication
{
public static void CreateAuthenticationToken(out string token, out string timestamp, string message = null)
{
const int merchantId = 123123;
const string secretKey = "sharedSecret";
message = message ?? string.Empty;
timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

using (var sha512 = SHA512.Create())
{
var hashBytes = sha512.ComputeHash(Encoding.UTF8.GetBytes(message + secretKey + timestamp));
var hashString = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
token = string.Concat("Svea ", Convert.ToBase64String(Encoding.UTF8.GetBytes(merchantId + ":" + hashString)));
}
}
}