Fetching and using Access Tokens


Access tokens are short lived JWT tokens that can identify either a user or an application. For an introduction to the JWT standard, see https://jwt.io/introduction.
Because the tokens are short lived and since they can not be refreshed on their own, the verification of them are simpler than compared to ID-tokens. This means that they can be validated without the need for an IMSG reverse proxy.
This document describes how to fetch and use Naviga ID access tokens.
The links in these instructions point to the stage environment. To access the production systems, simply remove .stage from all URLs. For example: Stage Access-Token Service: https://access-token.stage.imid.infomaker.io Prod Access-Token Service:https://access-token.imid.infomaker.io

Fetch access tokens

There are two ways to authenticate to retrieve an access token, either as a user or as an application.
Locally cache and reuse Access Tokens for as long as they are valid (i.e. not expired). Do not fetch a new access token for each request you perform to a service API such as CCA or OC.

Fetch access-token as logged in user

As a logged in user, using ID-token
Groups are only included in the access token if they have a "group to role"-mapping setup in Naviga ID Login.

Fetch access-token as application (using client credentials)

If you haven't yet created an application in Naviga ID, se the Managing Applications page and follow the instructions there.
As an application, using client credentials

Fetching access-tokens as application configured using scopes

To use scopes, the application must have been configured with allowedScopes when created (and not using groups). If that is not the case, you can either modify the application by removing the groups and add allowedScopes, or simply create a new application.
When fetching a token, in the scope field, specify the scopes that you wish to include in the token. If you specify more inclusive scopes than what is definied in the allowedScopes for your application, the req will fail. If you specify invalid scopes, such as with unit, service, role or pemission that does not exists in Naviga ID, the req will fail.
All scopes have the following format
Below is a list of examples of scopes
If allowed, the token will get the opencontent:view permission only in the gl-news unit
If allowed, the token will get the opencontent:view permission in all units in the org
If allowed, the token will get all permissions in the opencontet:readOnly role only in the gl-news unit.
If allowed, the token will get all permissions in the opencontet:readOnly role in all units in the org

Fetching access-token as application configured using groups

Note that group-based applications are our legacy way of configuring authorization. It is still supported, by we highly recommend to transition to scope-based applications.
CURL example. Start by storing client_id and client_secret in environment variable CLIENT_ID and CLIENT_SECRET respectively.
curl --data "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET" https://access-token.stage.imid.infomaker.io/v1/token
CURL example that stores token in environment variable NAVIGA_ACCESS_TOKEN.
export NAVIGA_ACCESS_TOKEN=$(curl --silent --data "grant_type=client_credentials&client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET" https://access-token.stage.imid.infomaker.io/v1/token | jq -r '.access_token')

Authenticate using an Access Token

Only send Access Tokens over HTTPS
Simply include the Access Token in the Authorization header whenever you perform a request to a Naviga ID enabled service API, such as CCA and OC.
Authorization : "Bearer $NAVIGA_ACCESS_TOKEN"
Do not include the ID-token cookie when executing requests to APIs. If the service is using an IMSG, there's a chance of a "Too many tokens"-error.
CURL example. Environment variable NAVIGA_ACCESS_TOKEN and NAVIGA_ORG needs to be set.
curl -H "Authorization: Bearer $NAVIGA_ACCESS_TOKEN" https://demo.stage.imid.infomaker.io/v1/org/$NAVIGA_ORG/test