Get token¶
Get a token that can be used for authentication
Prerequisites¶
client id
client secret key
username
password
C#¶
To get token, first create an instance of CrayonApiClient.
Then call Tokens.GetUserToken() method to get token.
var clientId = <clientId>;
var clientSecret = <clientSecret>;
var userName = <username>;
var password = <password>;
var client = new CrayonApiClient("https://api.crayon.com/");
var token = client.Tokens.GetUserToken(clientId, clientSecret, userName, password).GetData().AccessToken;
Using RestSharp:
var client = new RestClient("https://api.crayon.com/") {
Authenticator = new HttpBasicAuthenticator(clientId, clientSecret)
};
var request = new RestRequest("/api/v1/connect/token", Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "password");
request.AddParameter("username", userName);
request.AddParameter("password", password);
request.AddParameter("scope", "CustomerApi");
return client.Execute<TokenResponse>(request);
Request¶
Request Syntax:
Method |
Request URI |
---|---|
POST |
https://api.crayon.com/api/v1/connect/token/ |
Url encoded body parameters:
Name |
Type |
Description |
---|---|---|
username |
string |
Username of your API user. You can create an API user here: https://cloudiq.crayon.com/users/ |
password |
string |
Password of your API user. You can create an API user here: https://cloudiq.crayon.com/users/ |
grant_type |
string |
Use value “password” |
scope |
string |
Use value “CustomerApi” |
Request Headers:
The following HTTP request headers are supported
Header |
Type |
Description |
---|---|---|
Authorization |
Basic <base64 encoded string> |
Required. Basic token base64 encoded of ClientId:ClientSecret. |
Accept |
string |
Specifies the request and response type. |
Content-Type |
application/x-www-form-urlencoded |
Specifies the media type of the resource. |
Values sent in authorization header:
Name |
Type |
Description |
---|---|---|
clientId |
string |
Identifier created when you registrer your application in the customer portal. _You can register your application here: https://cloudiq.crayon.com/clients/ |
clientSecret |
string |
Secret password created when you registrer your application in the customer portal. _You can register your application here: https://cloudiq.crayon.com/clients/ |
Request Example:
POST "https://api.crayon.com/api/v1/connect/token/"
Accept : application/json
Content-Type: application/x-www-form-urlencoded
Authorization : Basic <base64 encoded ClientId:ClientSecret>
Post params (url encode values):
"grant_type": "password",
"username": "username",
"password": "password",
"scope": "CustomerApi"
Response¶
If successful, this method returns a TokenResponse resource in the response body.
{
"AccessToken": "2eUYzekFrZnF1RSIsImtpZCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSJ9.eyJjbGllbnRi10ZXN0LmF6dXJld2Vic2l0ZXMubmV0L2F1dGgvcmVzb3VyY2VzIiwiZXhwIjoxNDQ5NjY2Nzg4LCJuYmYiOjE0NDk1ODAzODh9.XFj4vbwDDEC6F5x89XhYK4D3tSHmgAn0DCZmafkbhxyTAGGEm-MUrGTLvpNQUg5Te5YL4x1nRb7h10Gwog1cwLMM1T-XFDfXg8uFYmK1iiyeSthdhTUUGFTaF6SJtj-1jYAuhcX9GLi-j1hE-RtxgrxQMQhoaLbV-MxPeiUSzBof8w3ohKZDhsLJPi_30cvHYOe-6NNUboJxAL43MLD7Rm1Z7t7AtehcAfvx_C3jHD2GeJVWZZFtyMay6T36avkxnmFoLU1o00JVnSpmYqUuoOAbM2TQsBHfL6pBzMZ0RCREYG7WQ",
"IdentityToken": null,
"Error": null,
"ExpiresIn": 20060,
"TokenType": null,
"RefreshToken": null
}