Skip to main content

Authorization

Now that you have access to the system and have tested the basic functionality, let's move on to the use of M2M authorization (machine to machine) in which the authentication generated by the user and password allows access by other applications through access keys.

Authorize Client [POST]

BASE URL
https://auth-hml.carbonext.com.br/auth/realms/co2free/protocol/openid-connect/token

This request validates the provided credentials and returns the generated token.

Parameter Attributes

ParameterDescription
client_idThe client's public credential key
client_secretThe client's private credential key
grant_typeclient_credentials

Response Attributes

ParameterDescription
accessTokenA token used to authorize user access.
token_typeThe token type
expires_inThe amount of time until the token expires, numbers in seconds
refresh_tokenThe refresh token provided in the authorization request

Example Request

var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
'client_id': '<your_client_id>',
'client_secret': '<your_client_secret>',
'grant_type': 'client_credentials',
'scope': 'roles'
});
var config = {
method: 'post',
url: 'https://auth-hml.carbonext.com.br/auth/realms/co2free/protocol/openid-connect/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : data
};

axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});

Example Response

{
"access_token": "kRjvJJpQpwWHoWKi-K_5SO0w0dkAqiO2QudmyoJxlTI",
"expires_in": 36000,
"refresh_expires_in": 0,
"token_type": "Bearer",
"not-before-policy": 0,
"scope": "profile email roles"
}