Contents
- API Authentication for Manage version 4.5 and above - API authentication is performed without the client-side computation of the 'apikey's' SHA1.
- API Authentication for Manage version 4.4 and below - API authentication requires SHA1 computation of ‘apikey’ on the client side.
Note: The API authentication procedure for 4.4 and earlier versions will continue to function with 4.5 application. To distinguish between the two strategies a client can use, the 4.5v API authentication has a new header. TLS is used to ensure transit security.
Overview
In Manage, users are assigned to a user role and a facility for a greater control and security. When a user is assigned to a facility, the user can only issue API calls for the assigned facility and role permissions. A role grants the user the ability to perform certain tasks. You can manage roles and assign facility to a user in the User Management section in the Manage Administration menu. Refer to the list of following articles:
- User Role Permissions
- Add Users and User Roles in Manage
- Assign a Facility to a User
When an API request is made, if the user role provides permission to the requested API and the user has access to the assigned facility, the request will be authorized and allowed to be complete. For example, users can request data from the sensors on the floor or area in the facility to which they have access. The API call returns a permission error if the user does not have access to the facility or the user role does not provide the permission to view data. Refer to the User Role Permissions for APIs.
API Authentication for Manage v4.5 and Above
Users must be authenticated to send or receive API requests to and from Manage. For authentication, send the following headers along with the REST API.
Generating the API Key
To generate an API key for a user, see Generate API Key. For API authentication, send the following Headers along with the REST API call:
- UserId – Username.
- Authorization – apikey and the generated API key copied from the Manage application.
For example, user Bob is assigned the following values:
- UserId: bob
- Authorization: apikey e511c7a4b04740f2f3c519209ad7429ac3f9f728b97c5d8cd1c88096987ad0d1
API Example:
>curl -s --get -H "UserId: bob" -H "Authorization:
apikey e511c7a4b04740f2f3c519209ad7429ac3f9f728b97c5d8cd1c88096987ad0d1" -H
"Accept: application/json" -k "http://localhost:8080/ems/api/switch-groups?facility=FLOOR&facilityId=5" -v -k
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /ems/api/switch-groups?facility=FLOOR&facilityId=5 HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.83.1
> UserId: bob
> Authorization: apikey e511c7a4b04740f2f3c519209ad7429ac3f9f728b97c5d8cd1c88096987ad0d1
> Accept: application/json
>
Note: Ensure that the API key and other credentials are entered in the request Header.
API Authentication for Manage v4.4 and Below
Users must be authenticated to send or receive API requests to and from Manage. For authentication, send the following headers along with the REST API.
- API key -- Unique identifier for the user (this is the user name, for example, Bob and the generated API key copied from the EM system).
- Timestamp -- Time, date, and day of the API call. This is included to avoid replay attacks.
- Authorization -- SHA-1 authorization key (Calculated using the API key and timestamp).
Generating the API Key
To generate an API key for a user, see Generate API Key. Then, determine the timestamp (ts), authorization token as explained below, and send the headers along with the REST API call.
For example, user Bob is assigned the following values:
- Username: bob
- API Key: 6eb6f07fd09b18dd61dd353dfb669820e7859cd3 (The API Key copied from Manage)
Time Stamp and SHA-1 Authorization
Calculate timestamp and SHA-1 authorization values for the user (for example, bob) as follows:
- Use the formula below to calculate timestamp (ts):
ts=echo $(($(date +%s%N)/1000000))
For example, if today's GMT date and time was Thursday, March 3, 2016, 7:36:51.032 PM, the timestamp would be 1457033811032
- ts: 1457033811032
- Use the following command to calculate SHA-1 authorization in Linux, for example.
SHA1="$(echo -n "$username$apikey$ts" | sha1sum -t | awk '{print $1}')".
- Authorization: e20ac2c963ccfacf23a1f70287286443820e66d1
For API authentication, send the following Headers along with the REST API call:
APIkey: bob (Note: The APIkey here is the username)
Authorization: e20ac2c963ccfacf23a1f70287286443820e66d1
ts: 1457033811032
API Example:
:~$ curl -s --get -H "ApiKey: bob" -H "Authorization: |
Note: Ensure that the API key and other credentials are entered in the request Header.
Comments
Article is closed for comments.