Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
In this section, you will find instructions on how to create a service account to authenticate with the Unico IDCloud platform.
To use server-to-server interactions, you need to request the creation of a service account through the project manager responsible for your company by providing the following information: company name, application name, name, email, and phone number of the person responsible for the application within the company. Separate accounts are required for the Homologation and Production environments.
Once this information is received, a service account responsible for authenticating your application will be created, and an email will be sent to generate the key pair for the account. A service account credential includes a unique account name, a company identifier (Tenant ID), and at least one key pair (public and private). After generating the keys, you will only receive the private key (a .key.pem file) along with the payload that must be used to construct the JWT. This payload will follow the format below:
If you need the public key for system configuration, please contact the project manager responsible for your account. Alternatively, you can generate a public key using the following OpenSSL command:
Still need help?
Didn't find something or still need help? If you're already a client or partner, you can reach out through our Help Center.
In this section, you will find additional resources related to authentication
In this section, you’ll find instructions on how to complete the authentication process on the Unico IDCloud platform
After creating and configuring a service account, your application needs to complete the following steps:
Create a JSON Web Token (JWT), which includes the header, payload, and signature.
Request an Access Token from the OAuth2 authentication platform.
Process the JSON response returned by the authentication platform.
If the response includes an access token, you can use it to make requests to Unico product APIs for which the service account has access permissions. (If the response does not include an access token, your JWT or token request may be incorrect, or the service account might lack the necessary permissions to access the requested resources.)
The access token generated in the above request has a default validity of 3600 seconds, but this may vary based on the security configuration set for your company. When the access token expires, your application must generate a new JWT, sign it, and request a new access token from the authentication platform.
A JWT (JSON Web Token) consists of three parts: a header, a payload, and a signature. The header and payload are JSON objects, which are serialized in UTF-8 and then encoded using Base64url encoding. This encoding ensures resilience against modifications due to repeated encoding operations. The header, payload, and signature are concatenated using a period (.
) separator.
A JWT is structured as follows:
The base text for the signature is formed in the following way:
The header consists of two fields that specify the signing algorithm and the token format. Both fields are mandatory, and each field has only one value. Service accounts rely on the RSA SHA-256 algorithm and the JWT token format.
As a result, the JSON representation of the header is as follows:
The Base64url representation is as follows:
This ensures that both header and payload are properly encoded before signing, which is crucial for secure authentication.
The JWT payload contains information about the JWT, including the requested permissions (scopes), the account requesting access, the issuer, the time the token was issued, and the token's lifespan. Most fields are mandatory. Like the JWT header, the payload is a JSON object and is used in the composition of the signature.
The required fields in the JWT are shown in the table below. They can appear in any order within the payload.
Understand how the conversion works for the issuance (iat) and expiration (exp) fields of the JWT, and also see examples of how to use the values of these fields here. Additionally, the "iat" field should reflect the current time in the required format, and the "exp" field must adhere to the calculation below:
The representation of the mandatory JSON fields in the JWT payload is as follows:
The JSON Web Signature (JWS) specification is the mechanism that guides the calculation of the signature for a JWT. The input content for the signature calculation is the byte array of the following content:
The same algorithm specified in the header of the JWT must be used for the signature calculation. The only signature algorithm supported by the OAuth2 authentication platform is RSA using SHA-256. It is expressed as RS256 in the alg field of the JWT header.
Sign the UTF-8 representation of the input content using SHA256withRSA (also known as RSASSA-PKCS1-V1_5-SIGN with SHA-256 hash) with the private key that was created and associated with the service account (the .key.pem file generated from the request received by email). The output content will be a byte array.
The signature must then be encoded in Base64url. The header, payload, and signature must be concatenated with a period (.). The result is the JWT. It should be in the following format: {Header in Base64url}.{Payload in Base64url}.{Signature in Base64url} Below is an example of a JWT token before Base64url encoding:
Below is an example of a JWT token before Base64url encoding:
Below is an example of the JWT that has been signed and is ready for transmission:
It is also possible to use pre-established libraries to create the JWT. As a reference, you can find a list of libraries on the jwt.io website.
After generating the signed JWT, an application can use it to request an access token. The access token request is a POST HTTPS request, and the body must be URL encoded. The URL is as follows:
The parameters below are mandatory in the request:
If the JWT and the access token request were properly formed and the service account has the necessary permissions, then the response from the authentication platform returns a JSON object containing an access token. Here’s an example of a response from the platform:
The access token returned in the “access_token” field of the JSON object is also a JWT that should be used for the APIs of Unico’s products. If an error occurs in the request, you can check the type of error in the error table by clicking here.
The duration of the access token is variable. Its duration is specified in the "expires_in" field, returned along with the access token. The same access token should be used during its validity for all calls to the product APIs.
Do not request a new access token until the validity of the current token is nearing its end. We recommend a margin of 600 seconds (10 minutes). To do this, perform the calculation:
Where token.exp is the timestamp of the token's expiration.
By default, the token sent to the company is valid for 1 hour, but this can be changed. It is recommended to always use the expires_in
as a reference and subtract 600 seconds from it to request a new token.
Examples:
A new access token can be requested when there are 10 minutes left until expiration.
Do not use a fixed time to obtain a new token, as the duration of the received token may be shorter than the established time, which will result in service usage failures.
¹ According to RFC 4648 for BaseN encoding, the Base64url format is similar to the Base64 format, except that the character = should be omitted, and the characters + and / should be replaced with - and _, respectively.
² JSON Web Signature: https://tools.ietf.org/html/rfc7515.
Still need help?
Didn't find something or still need help? If you're already a client or partner, you can reach out through our Help Center.
In this section, you will find the possible errors that may occur when trying to authenticate on the Unico IDCloud platform.
The errors returned in the request can be identified by the codes below and have the following structure:
Name | Description |
---|
In this section, you will find the Postman collection for the REST API to authenticate on the Unico IDCloud platform
Download the file below, import it into Postman, and replace the values of the parameters "service_account," "tenant_id," and "secret_key" to test the request.
In this section, you will find the full technical specifications for the authentication method required to use the IDCloud platform’s REST APIs
To use the IDCloud platform, you must authenticate via access token using the OAuth2 authentication system. Unico’s OAuth2 authentication supports server-to-server interaction between a web application and Unico's services.
In this setup, you will need a service account, an impersonal account that belongs to your application rather than to an individual user. Your application calls Unico’s APIs on behalf of the service account, so no users are directly involved. This setup is called “two-legged OAuth,” or “2LO.” Typically, an application uses a service account when it calls Unico’s APIs to work with its own data rather than user data.
This is the first essential step in your implementation, so be sure not to skip it.
Still need help?
Didn't find something or still need help? If you're already a client or partner, you can reach out through our .
In this section, you will find an example of implementing authentication for the Unico IDCloud platform in JavaScript
Name | Description |
---|---|
Name | Description |
---|---|
Still need help?
Didn't find something or still need help? If you're already a client or partner, you can reach out through our .
Still need help?
Didn't find something or still need help? If you're already a client or partner, you can reach out through our .
Still need help?
Didn't find something or still need help? If you're already a client or partner, you can reach out through our .
iss
The identifier of the service account within the company.
scope
A space-delimited list or a list separated by the plus sign (+) of the permissions that the application is requesting. If all permissions of the account are required, use the asterisk sign (*) for that purpose.
aud
Address of the authentication platform that issues access tokens. This value must always and exactly be https://identityhomolog.acesso.io Common cases that DO NOT work:
Inserting a trailing slash at the end of the address: https://identityhomolog.acesso.io/
Using the HTTP protocol instead of HTTPS: http://identityhomolog.acesso.io
exp
The expiration time of the token, specified in seconds since 00:00:00 UTC, January 1, 1970. This value has a maximum time of 1 hour after the moment of issuing the JWT. This value must be numeric. Common cases that DO NOT work:
Using quotes to delimit the value. For example: “1524161193” is a string and will not work. However, 1524161193 is a number and will work.
iat
The moment of issuing the JWT, specified in seconds since 00:00:00 UTC, January 1, 1970. This value must be numeric.
Using quotes to delimit the value. For example: “1524161193” is a string and will not work. However, 1524161193 is a number and will work.
grant_type
Use the following text, URL-encoded if necessary: urn:ietf:params:oauth:grant-type:jwt-bearer.
assertion
The JWT, including the signature.
1.0.1 | Check if the ID provided in the formation of "iss" is the correct tenant ID given during the generation of the private key. |
1.0.14 | Check with the project manager if the application being used is active. |
1.1.1 | The "scope" parameter was not provided in the payload of the JWT used in the request. |
1.2.4 | The JWT used in the request has expired. Check the value specified in the "exp" field of the payload. |
1.2.5 | The JWT used in the request cannot be validated. Verify the parameters provided and ensure that it was signed correctly. |
1.2.6 | The private key used to sign the JWT in the request is no longer acceptable. Request new credentials for the account used. |
1.2.7 | The JWT used in the request is no longer acceptable as it has already been used. Generate a new token to make a new request. |
1.2.11 | The account used is not active. |
1.2.14 | The account used does not have the necessary permissions. |
1.2.18 | The account used has been temporarily locked due to exceeding the number of invalid authentication attempts. |
1.2.19 | The account used is not authorized to impersonate another user account (remove the "sub" parameter from the payload). |
1.2.20 1.2.21 | Failed to decode the JWT used in the request. Use a new token by including only the fields specified in the "Mandatory Fields" and "Additional Fields" sections, adhering to the naming, semantics, and type of each field. |
1.2.22 | The JWT used in the request contains additional fields in the payload that are not allowed. Use a new token by including only the fields specified in the "Mandatory Fields" and "Additional Fields" sections, adhering to the naming, semantics, and type of each field. |
1.3.1 | The account used has source IP restrictions. |
1.3.2 | The account used has access date/time restrictions. |