The Web API uses token-based authentication to enable you to make calls without needing to pass user details every time.
To receive an access token you must make an initial request to the Web API providing user name, password, database and role.
If the login is successful, you will receive an access token in response, along with the token expiration time and a refresh token which can be used to reset the session before it times out.
For every subsequent call, you must pass the token as the 'Authorization' parameter. For example:
request.AddHeader("Authorization", "Bearer " + _accestoken); |
https://localhost/webapi/api/token
POST
Parameter |
Type |
Description |
grant_type |
string |
Use value "password" to use the Password grant type for authorisation |
username |
string |
Your user name |
password |
string |
Your password |
database |
string |
The name of the database you wish to log in to |
role |
string |
Your role code |
Requesting an access token to use the Web API, using the RestSharp library.
var client = new RestClient(_baseurl + "token"); var request = new RestRequest(Method.POST); request.AddParameter("grant_type, "password"); request.AddParameter("username", "rde"); request.AddParameter("password", "macrop"); request.AddParameter("database", "demo"); request.AddParameter("role", "FullUser"); request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request); JObject rss = JObject.Parse(response.Content);
return (_accesstoken != null); |
The server replies with an access token and refresh token:
{ "access_token":"5c2vPuV9owxdkYTGe2X-TXWm3QO-PaOQiy-JqFXuYgYV8qt59-j56ByL_OV8PmAcyxbfuZtDfv0nZ- mQ5jiWLsdQW5Ca_X88D3xV0c1HIpsgqlQkS1gKy5tCR6Gk1c1OH92MEdB67U7h4hJAGCGMRQ5DlTo2tIDN_2u-_uhOpa46zzB4Ptny7gNaglkE3kdBbC22-A5pO86nL-c4glXspNLpjPlgYNl9JDmsW-VNzVOQmqIjEj6dNY9MZCQp4HHBhEZgPiDzqrTKPxbqIF_juz_kEaD-eusk7YmgTFrlxgEPH1DGi6ime1DFrZk_EUt0bLMINoHS11AJodvOAKb9AHdB4HyQIARMTB21WCrGTo4", "token_type":"bearer", "expires_in":299, "refresh_token":"2WXGh5SQ4sFCAryB1udTcD9ZCY9G9H6VA7GR5JnIAxQQcyFILQPsIrqnSy_VatYgcsC2KXNRtqD92KYpJOmakApw5IFNlqorkh8SHHS4VQzSlsMv8XIZQOr-LamsejHOK-2-TYyzElKe1rVndRHNQKomyHWt40HD4ZjoJYLcd2_2W2YUElzY72HgRZqouCgz8I6P8bMHubDJWaf8OqPzNqxKlS7plTBUOFaybcLfy0ILDac4PpiVAYjsYU50BkGM0b3_o0vfH8y2Yh-_XVINAQ7G52hrCf-Ieh7aIP0f_urJwHLloyOThnEayA67_H39eY_ARO_ViTcnDmDNhH8g-sUH0F6DxhipUhcyZUBrpss" } |