Authentication
Your application must be authenticated to use the Diyalog API. Diyalog uses an AccessKeyId and AccessKeySecret pair for this. First, request the access key id and secret for your application from your Diyalog admin.
Credentials required to make API requests :#
- AccessKeyId : The access key id created specifically for your application.
- AccessKeySecret : The secret key created specifically for your application. This key is used to sign your requests.
To call the Diyalog APIs, you must authenticate every request. The Diyalog Platform uses the HMAC Authentication mechanism for authentication.
- HMAC Authentication
Security#
Transport Layer Security (TLS) is required for authentication. API requests must be encrypted with SSL.
HMAC Authentication#
The Diyalog API uses the HMAC Authentication algorithm and mechanism to authenticate HTTP requests. This mechanism verifies the integrity of each request and that it was made by an authorized application.
After the Diyalog admin user creates the AccessKeyId and AccessKeySecret pair for your application, you must use these credentials to compute the MAC (Message Authentication Code) of every API request with the HMAC SHA256 algorithm and send it in the header of your request. The request time and the employee ID of the person making the request must also be added to the header. The Diyalog Platform uses this information to authenticate your request, after which you will receive a response from the API.
For security, you must use HTTPS/TLS.
The fields you must add to the header of every API request for HMAC authentication are as follows :#
- x-dlg-date
The time at which the request is made. It must be in the "EEE, dd MMM yyyy HH:mm:ss Z" format.
x-dlg-date : "EEE, dd MMM yyyy HH:mm:ss Z"For example: x-dlg-date : Tue, 09 Mar 2021 13:28:32 +0000
- Use English day and month names and a numeric time zone offset such as
+0000or+0300. - Make sure your timestamp does not drift more than +/- 15 minutes from the time used by the Diyalog server; otherwise your request will fail.
- A date the server cannot parse in this format is rejected.
- Use English day and month names and a numeric time zone offset such as
- x-dlg-requester-userid
The employee ID of the user making the request, or that user's unique id in your system. This value is used for audit logs.
x-dlg-requester-userid : “userId of requester”For example: x-dlg-requester-userid : 45186
- x-dlg-authorization
Your API request is authorized with the request signature you put in this field. The x-dlg-authorization header is built by concatenating the following values.
x-dlg-authorization : "DLGA " + AccessKeyId + ":" + SignatureFor example : x-dlg-authorization : DLGA 1234567-8ABC-DEF0-5432-56712ABCDEF5:4J2OtxTeMpyfMad4y26RaKA/rrk=
Building the x-dlg-authorization header#
- Build the string to sign: the five values below, joined with a newline (
\n) between each. - Compute the HMAC-SHA256 of the UTF-8 bytes of that string, using your AccessKeySecret as the key.
- Base64-encode the result. This is the signature.
- Send
DLGA(with a trailing space) + AccessKeyId +:+ signature in thex-dlg-authorizationheader.
The values in the string to sign:
| Value | Description |
|---|---|
| HTTP-method | The HTTP method in upper case, e.g. POST or GET. |
| Content-Type | The media type the server sees, without parameters. For a JSON body this is always application/json, even if you send application/json; charset=utf-8. For a request with no body and no Content-Type header, it is none/none. |
| Date | Exactly the value you send in the x-dlg-date header. |
| Body | The request body exactly as sent, as a string. For a request without a body, an empty string. |
| RequestPath | The path of the request URI, e.g. /v1/reporting/getonlinehelplist for https://<DIYALOG-SERVER-API-ENDPOINT>/v1/reporting/getonlinehelplist. |
Example string to sign, with the body sent as compact JSON:
Avoid signature mismatches
- Sign the exact body you send. Serialize the JSON once and use the same string for the signature and the request. Compact, single-line JSON avoids differences in whitespace and line endings.
- Sign
application/json, not the full header value. Many HTTP clients add; charset=utf-8to theContent-Typeheader (for example .NETStringContent). The server ignores the charset when it builds the string to sign. - GET requests: if you send no
Content-Typeheader, signnone/none. If you sendContent-Type: application/jsonwith an empty body, signapplication/json. - Clock: keep the client clock in sync; the date may differ from the server time by at most 15 minutes.
Code examples#
Both examples call the getonlinehelplist Reporting API. They read the API endpoint and credentials from the DIYALOG_API_URL, DIYALOG_ACCESS_KEY_ID and DIYALOG_ACCESS_KEY_SECRET environment variables. They were checked against the server's signature validation on the same HTTP stack the server uses.
- Java (11+)
- C# (.NET 6+)
- curl
Summary#
- Get the AccessKeyId and AccessKeySecret for your application from your Diyalog admin.
- Build the request body as a string.
- Set
x-dlg-dateto the current time in theEEE, dd MMM yyyy HH:mm:ss Zformat. - Set
x-dlg-requester-useridto the employee ID (or unique user id in your system) of the person the request is made for. - Build the string to sign from the HTTP method, content type, date, body and request path.
- Compute the HMAC-SHA256 of the string with your AccessKeySecret and Base64-encode it.
- Set
x-dlg-authorizationtoDLGA+ AccessKeyId +:+ signature, and send the request over HTTPS.
HMAC Authentication Errors#
If a request cannot be authenticated or authorized, the server returns one of the following errors. The message is returned as plain text.
| HTTP status | Message | Description |
|---|---|---|
| 400 | Required headers not found | One or more of the x-dlg-date, x-dlg-requester-userid or x-dlg-authorization headers are missing. |
| 400 | Authorization failed due to data format not valid | The x-dlg-authorization value after DLGA is not in the AccessKeyId:Signature form. |
| 400 | Date format is invalid. EEE, dd MMM yyyy HH:mm:ss Z is requied | The x-dlg-date value cannot be parsed in this format. The message text is returned as shown, including its spelling. |
| 401 | Authorization failed | The x-dlg-authorization header does not contain DLGA , the AccessKeyId is unknown, or the signature is not correct. |
| 401 | You have no permission on this operation. Contact your admin. | The signature is correct, but your access key has no permission for this API group (for example reporting or push). |
| 403 | Request time may not be correct. | The x-dlg-date value differs from the server time by more than 15 minutes. |