Get an Access Token
After registering an OAuth application in EmpowerID, the next step for working with the API is to use the credentials generated for that application – which consists of the API Key, the Client ID and the Client Secret – to get an access token. The access token is what authorizes you to make API calls. The resources that can be manipulated vary, depending on the Access Levels associated with the application user. Access tokens can be issued as OAuth 2.0 tokens or JWT tokens. In this topic, we demonstrate getting an OAuth 2.0 token.
How to get an access token
To get an access token, you need to make a POST
request to https://<Your_EmpowerID_Web_Server>/oauth/v2/token
with the following header and data value pairs:
Headers
Key | Value |
---|---|
Authorization | This is the Basic authentication scheme for the EmpowerID Person requesting the access token. To use this scheme, you set the value to the base-64 encoded value of the person's username and password. To get this value, you can visit one of many websites that provide this service, write your own code, or use a REST client like Postman. |
Content-Type | application/json |
Request Data
Request data is sent to the API in JSON format
{
"client_id": "{The Client ID of the OAuth app you created above}",
"client_secret": "{The Client Secret of the OAuth app you created above}",
"grant_type": "password"
}
Response
If the request is successful, you should receive a JSON response that looks similar to the following:
{
"access_token": "WER1RFdjUVF1OE52ekdWZjJIQjMzSHVqcERQT0p5c...aZW",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "YnQrRHhuyYmNidzY3MTFSVnE1Q1BLN1RuZ1liOH...WQ==",
"id_token": "null",
"error": "",
"error_description": "null"
}
Code Examples
Using the .NET Client Library
1. Initialize ClientSettings
by passing the client_id
, client_secret
, redirect_uri
, token_endpoint
, authorization_endpoint
, tokeninfo_endpoint
and userinfo_endpoint
. Also initialize a new ResourceOwnerPasswordGrant
by passing the clientSettings
model.
var clientSettings = new ClientSettings(
“client_id”,
“client_secret”,
“redirect_uri”,
“https://<EID Server>/oauth/v2/token”,
“https://<EID Server>/oauth/v2/ui/authorize”);
var handler = new ResourceOwnerPasswordGrant (clientSettings);
2. Call the GetAccessToken()
method to retrieve the access_token
and refresh_token
When using cURL, be sure to use double quotes unless you are making the request from a non-Windows OS.
cURL
Ajax
Postman Example
Open the Postman app on your machine.
In Postman, open a new tab, select POST as the HTTP method and enter https://{FQDN_Of_Your_EmpowerID_Web_Server}/oauth/v2/token.
Select the Headers tab add the above mentioned key/value pairs.
Select the Body tab, click raw and then add the below JSON:
Click Send.
If the request is successful, you should receive a JSON response with the access token and refresh token.
IN THIS ARTICLE