API uses the OAuth 2.0 protocol for authentication and authorization. Basic pattern follows four steps:
To begin, obtain client credentials from the provider. Client credentials are:
Before client can access API methods, it must obtain an access token that grants access. Client sends the token request to the API authorization server, which returns access token and refresh token. Client extracts tokens from the response, and stores them for later use.
URL: https://{provider host}/{culture}/token
URL example: https://demo.s2.renteon.com/en/token
HTTP method: POST
Params format: BODY: application/x-www-form-urlencoded
Params:
| Name | Description | Example |
|---|---|---|
| grant_type | Constant value "password" | password |
| username | Together with password identifies individual user in provider system | apiUser10 |
| password | Together with username identifies individual user in provider system | pa$$w0rd |
| client_id | Provider issued identifier for consumer application | B2B.SampleAgency |
| signature | Hashed signature used for client authentication. Generated with preset pattern and algorithm, and provided "secret" and "salt". | NXxTaXh4dTdGnVG0jUFSy0y7KjcwL... |
| salt | Random data that is used as an additional input to a one-way function that hashes "signature" param. Valid "salt" length range is 8 - 50 | 20160204183122 |
{
"access_token":"6J3QE7m7Cb5F1FiuXo4LBV2fOfp04FdjoI...",
"token_type":"bearer",
"expires_in":3599,
"refresh_token":"1ec55c2b8a8f4503a99bf917ce5452c8",
".issued":"Tue, 08 Mar 2016 14:59:49 GMT",
".expires":"Tue, 08 Mar 2016 15:59:49 GMT"
}
Token request should be signed with hashed signature used for client authentication, provided in parameter "signature". Parameter "signature" value should be generated for every authorization request as base64 encoded string representation of SHA512 hash of composite key built using following pattern: {username}{salt}{secret}{password}{salt}{secret}{client_id}
IMPORTANT: Make sure to use random "salt" parameter for each authorization request.
IMPORTANT: Make sure to safely store and use "secret" parameter, as it should never be accessible to public.
using System; using System.Security.Cryptography; using System.Text; string username = "UU"; string password = "PP"; string clientId = "CC"; string salt = "00"; string secret = "SS"; string compositeKey = username + salt + secret + password + salt + secret + clientId; HashAlgorithm hashAlgorithm = new SHA512CryptoServiceProvider(); byte[] byteValue = Encoding.UTF8.GetBytes(compositeKey); byte[] byteHash = hashAlgorithm.ComputeHash(byteValue); string signature = Convert.ToBase64String(byteHash);
import java.security.MessageDigestSpi;
import org.apache.commons.lang3.StringUtils;
String username = "UU";
String password = "PP";
String clientId = "CC";
String salt = "00";
String secret = "SS";
String compositeKey = username + salt + secret + password + salt + secret + clientId;
MessageDigest md = MessageDigest.getInstance("SHA-512");
md.update(str.getBytes());
byte byteData[] = md.digest();
String signature = StringUtils.newStringUtf8(Base64.encodeBase64(byteData, false));
$username = "UU";
$password = "PP";
$clientId = "CC";
$salt = "00000000";
$secret = "SS";
$compositeKey = $username.$salt.$secret.$password.$salt.$secret.$clientId;
$hash = hash("sha512" , $compositeKey, true);
$signature = base64_encode($hash);
Authorization server responds with error messages to invalid authorization requests. For security reasons, errors are not descriptive, but they contain error code. List of possible error codes with description is provided here:
Client sends access token to any of available API methods. Token is sent in an HTTP authorization header.
| HTTP header key | HTTP header value | Example |
|---|---|---|
| Authorization | Bearer {access token} | Authorization: Bearer 0Byx0sCZEYhjdQEVEzhe7hH... |
The access token has a limited life time expectancy. The "expires_in" parameter passed along at the roken response stage provides tokens life time in seconds. If an expired token is used the API will respond with unauthorized response error (HTTP status 401). This means client should use the refresh token to generate new access token. If refresh token is no longer valid, the client repeats the process.
There is the possibility that a granted token might no longer work. A token might stop working for one of the following reasons:
URL: https://{provider host}/{culture}/token
URL example: https://demo.s2.renteon.com/en/token
HTTP method: POST
Params format: BODY: application/x-www-form-urlencoded
Params:
| Name | Description | Example |
|---|---|---|
| grant_type | Constant value "refresh_token" | refresh_token |
| refresh_token | Previously obtained and stored "refresh_token" | 2b87030489014cb0b512acda71d5a945 |
| client_id | Provider issued identifier for consumer application | B2B.SampleAgency |