Authentication Basics
Before you can start using any service you need a valid token which you can receive through authentication. Enreach API uses OAuth 2.0. This token is then needed to be provided for every API call made.
The authentication flows supported at the moment are:
- Client Credentials. See Client Credentials Grant for more details
- Authorization Code.
Find below the flow to authenticate and collect the information, such as account id, required to interact with the Enreach API.
Sequence of authentication and profile reading
Let's look into code examples of the supported authentication flows.
To authenticate to Enreach API, the client_id and client_secret are required. Please reach your contact person for this information.
Examples
client_credentials authentication flow
POST oauth/token
Request Headers:
content-type:"application/x-www-form-urlencoded"
host:"api.host.url"
Request Body:
grant_type:"client_credentials"
scope:""
client_id:"your client id"
client_secret:"your client secret"
{
"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"token_type":"bearer"
}
authorization_code authentication flow
POST oauth/authorize?response_type=code&client_id=your_client_id&redirect_uri=your_redirect_uri
Request Headers:
content-type:"application/x-www-form-urlencoded"
host:"api.host.url"
Request Body:
username:"your username"
password:"your password"
POST oauth/token
Request Headers:
content-type:"application/x-www-form-urlencoded"
host:"api.host.url"
Request Body:
grant_type=authorization_code
code=your_authorization_code_from_previous_response
client_id=your_client_id
client_secret=your_client_secret
redirect_uri=your_redirect_uri
Response Body:
{
"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"refresh_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c",
"token_type":"bearer"
}
The access_token should be sent in each subsequent request as Authorization Header. See an example in "Example of collecting profile of authenticated user" below.
Collecting profile of authenticated user
Once the authentication is successful, another request should be executed to get the profile of the API client.
GET v1/profile
Request Headers:
authorization:"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
host:"api.host.url"
{
"account_id": "cd14708b-cecf-4b2e-a207-1721ff46f8c1",
"user_id": "245c73c8-9a11-499a-ae7d-f82b4c38ed7d",
"user_name": "your_display_name",
"web_login_name": "your_email"
}