Skip to main content

Using Client Credentials

Requirements

As explained in the Authentication page, you will need to request a set of Client Credentials from an authorized reseller. Once you have the Client ID, Client Secret, and API Key you can start building.

Getting an Access Token

To get an Access Token, perform a

POST
request to the token URL https://auth.weightron.cloud/oidc/token providing the grant_type, client_id, and client_secret in the body. A scope can also be provided if necessary.

An API Key is not required for the token request.

When using Postman, set the body type to x-www-form-urlencoded and add each key required and its value. Under the Authorization tab select No Auth.

note

Under the Authorization tab, you can select OAuth 2.0 and enter your credentials under Create New Token.

Variables are used in the example below to hide the ID and Secret values.

Token Request GIF

A JSON response is returned containing the Access Token and the number of seconds until token expiry.

Response
{
"access_token": "<ACCESS_TOKEN>",
"expires_in": 300,
"token_type": "Bearer"
}

Checking Access

This step is not required during normal operation, however it can be used for testing the API Key and Access Token.

Perform a

GET
request to the access endpoint https://api.weightron.cloud/access to check what application/s the provided credentials have access to. The Authorization and x-api-key headers are required for all request to the API.

The Authorization header containing the bearer access token from the previous step Authorization: Bearer ..., and the x-api-key containing the API Key value supplied by your authorized reseller.

Under the Headers tab, add a key for x-api-key and add the value required.

Under the Authorization tab select Bearer Token and enter the Access Token from the previous step.

Variables are used in the example below to hide the ID and Secret values. Access Check GIF

All API responses are returned in a JSON format containing an Object with a timestamp and data key. See Response Format for more info.

Response
{
"timestamp": "2024-09-20T15:06:20.323Z",
"data": [
{
"_id": "66840a91a752c27bf3c886f2",
"name": "Documentation Example",
"expiry": "2030-09-20T22:59:59.999Z",
"company": {...}
}
]
}

In this case the /access endpoint returns an array of Application objects the OIDC client has access to. The _id of the object is the value to be used for future API requests when an ApplicationID is required.

Using the above response you could get a list of Collections within the Application by sending a request to:

GEThttps://api.weightron.cloud/66840a91a752c27bf3c886f2/collections

Convenience with Postman

When using Postman it is possible to configure an entire collection to use the same authorization rules. Start by creatng a new collection to save your queries into. Click the + button and select Blank Collection.

Postman Collection

In the right pane, click the Authorization tab and set the Auth Type to OAuth 2.0.

Postman Config

Then enter the following details into the Configure New Token section:

FieldValue
Token NameAny value.
Grant TypeClient Credentials
Access Token URLhttps://auth.weightron.cloud/oidc/token
Client IDClient ID Value supplied by your authorized reseller.
Client SecretClient Secret Value supplied by your authorized reseller.
ScopeSpace-seperated list of scopes.
For Client Credentials offline_access is the only accepted optional value. openid is required for all requests.
Client AuthenticationSend as Basic Auth Header

Once configured click the Get New Access Token button at the bottom of the right pane. A modal will appear while Postman runs the authorization query, a message should appear with Authentication complete. A list of tokens will follow after some time, click Use Token in the top right of the modal. All requests made will now use the selected token.

Refresh Tokens

If the offline_access scope has been provided in the token request a Refresh button will be available under the Current Token section in the collection Authorization pane. Clicking this will refresh the token and assign it for use going forward. Tokens are only valid for 5 minutes so this process may need to be repeated multiple times during your time building the integration.