Authorization to APIs

This page describes how to authenticate and authorize your calls to our APIs using standard OpenId Connect

Create a service account

Service accounts provide an identity for your processes to access our APIs. They can authenticate themselves using either a Public Key or Password Authentication.

We recommend that you use Public key authentication which doesn't require sending secrets over the network.

You will need a private key to sign your access token requests, and a corresponding public key that our identity server will use to verify the signature.

Generate an RSA private key

openssl genrsa -des3 -out private.pem 2048

OpenSSL will ask you for a passphrase that will be used to encrypt the private key file.

Generate the corresponding public key

openssl rsa -in private.pem -outform PEM -pubout -out public.pem

Enter the private key passphrase when prompted.

Create the service account

Please reach out to your Technical Consultant to request a service account to be created. Specify that you chose Public Key Authentication and provide your public key. They will give you in return a Client ID and tenant ID that you will need in the following steps.

Obtaining access tokens

Access tokens can be obtained using the OpenId Connect Client Credentials grant.

The token endpoint to use is: https://iam.attraqt.io/auth/realms/${tenantId}/protocol/openid-connect/token where ${tenantId} is the identifier of your Attraqt tenant.

triangle-exclamation

The process differs depending on whether you are using Public Key or Password authentication.

Service accounts with the JWT authentication method need to send a JWT signed with their private key to get access tokens, as described in RFC 7523arrow-up-right.

The basic steps are:

  1. Build a JWTarrow-up-right with the following claims:

    • iss: your client ID (c.f. previous step)

    • sub: also your client ID

    • aud: the token endpoint

    • jti: a uniquely generated ID

    • exp: a rather short expiration time, one minute is more than enough.

  2. Sign the JWT with the private key you generated earlier.

  3. Send a client_credentials grant request to the authorization server token endpoint.

  4. Use the access_token in the response to obtain Requesting Party Tokens that will be needed to authenticate your requests to Attraqt private APIs (see below).

Node.js example

Java example

To work with the Java SDK, it is easier to convert your private key to the PKCS12 format:

And you can generate JWTs with Nimbus OAuth 2.0 SDKarrow-up-right:

  • Apache Maven:

  • Gradle:

Sample Code

Authenticating API calls

Calls to the Attraqt API must be authenticated with an Authorization header of type Bearer containing the acess token, for example:

You can use the access token as many times as you want before its expiration.

triangle-exclamation

Access token expiration

Access tokens expire after a time given in the expires_in field of the identity server response. You will then need to get a new one using the same HTTP query.

Last updated