Authentication

The Akiles API uses the standard RFC-6479 OAuth 2.0 protocol for authentication.

OAuth allows your app to interactively request access to customers’ Akiles organizations and obtain access tokens for them. This makes the experience smoother and more secure, since the customer doesn’t have to manually copy and paste a sensitive API key.

This section is not intended to be a full explanation on how OAuth works, just a quick reference to get started. For more info, consult online documentation about OAuth.

Client ID and Client Secret

Your OAuth application needs a Client ID and a Client Secret to operate.

To obtain your application’s Client ID and Secret, create an application in the Developer Center.

Redirect URIs

Register every redirect URI that your application uses in the Developer Center.

The consent page tells the user the redirect URI’s host. When the user allows your application, Akiles remembers it for that redirect URI only. If you send the user to another redirect URI, the consent page shows again.

Token types

Authorization flow

  1. Generate a cryptographically-secure random string state and store it somewhere you can access it later (e.g. a cookie)
  2. Start the flow by redirecting the user to the following URL:
https://auth.akiles.app/oauth2/auth?client_id=CLIENT_ID_HERE>&redirect_uri=https://your-app.example.com/redirect&response_type=code&scope=full_read_write offline&state=STATE_HERE
  1. The Akiles authorization server will prompt the user to choose a user account and organization.
  2. The Akiles authorization server will ask the user to authorize your requested scopes.
  3. The user gets redirected to your redirect_uri:
https://your-app.example.com/redirect?code=CODE_HERE&scope=full_read_write offline&state=STATE_HERE&iss=https://auth.akiles.app
  1. Check the state you have received matches the original state you stored. If it doesn’t, abort. This is necessary to protect against CSRF / session poisoning attacks. If your app uses more than one authorization server, also check that iss is https://auth.akiles.app. If it isn’t, abort. This protects against mix-up attacks (RFC 9207).
  2. Exchange the authorization code for the access and refresh tokens.
POST https://auth.akiles.app/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
client_id=CLIENT_ID_HERE
client_secret=CLIENT_SECRET_HERE
code=CODE_HERE
Warning

The authorization code is one-time-use only, and expires after 15 minutes. Keep this in mind when testing: you can’t simply retry the exchange request, you have to do the flow from the start every time.

HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
    "access_token": "ACCESS_TOKEN_HERE",
    "expires_in": 3599,
    "refresh_token": "REFRESH_TOKEN_HERE",
    "scope": "full_read_write offline",
    "token_type": "bearer"
}
  1. You’re done! Save the access token and refresh token.

You can now use the access token to make API calls on behalf of the user’s organization. Just include an Authorization: Bearer header with the access token:

GET https://api.akiles.app/v2/organization
Authorization: Bearer ACCESS_TOKEN_HERE

The access token expires in 1 hour. You can obtain new access tokens with the refresh token.

PKCE

The Akiles authorization server supports PKCE (RFC 7636). PKCE protects the authorization code: if somebody steals the code, they cannot exchange it without the code_verifier, which never leaves your server.

PKCE is optional. It does not replace the Client Secret: the token request still needs it.

To use PKCE:

  1. Generate a cryptographically-secure random string code_verifier, 43 to 128 characters long, with only the characters A-Z, a-z, 0-9, -, ., _ and ~. Store it together with the state.
  2. Compute code_challenge as the base64url encoding, without = padding, of the SHA-256 hash of code_verifier.
  3. Add code_challenge and code_challenge_method=S256 to the authorization URL:
https://auth.akiles.app/oauth2/auth?client_id=CLIENT_ID_HERE&redirect_uri=https://your-app.example.com/redirect&response_type=code&scope=full_read_write offline&state=STATE_HERE&code_challenge=CODE_CHALLENGE_HERE&code_challenge_method=S256
  1. Add code_verifier to the token request:
POST https://auth.akiles.app/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code
client_id=CLIENT_ID_HERE
client_secret=CLIENT_SECRET_HERE
code=CODE_HERE
code_verifier=CODE_VERIFIER_HERE

For example, the code_verifier dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk gives the code_challenge E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM.

Things to know:

Require PKCE

In the Developer Center, you can turn on “Require PKCE” for your application. Then the authorization server refuses every authorization request without a code_challenge.

Refresh token flow

POST https://auth.akiles.app/oauth2/token
Content-Type: application/x-www-form-urlencoded

grant_type=refresh_token
client_id=CLIENT_ID_HERE
client_secret=CLIENT_SECRET_HERE
refresh_token=REFRESH_TOKEN_HERE
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8

{
    "access_token": "NEW_ACCESS_TOKEN_HERE",
    "expires_in": 3599,
    "refresh_token": "NEW_REFRESH_TOKEN_HERE",
    "scope": "full_read_write offline",
    "token_type": "bearer"
}

Store both the new access and refresh tokens. The old refresh token, once used, is no longer guaranteed to keep working forever.

Scopes

Troubleshooting

I’m not getting any refresh token, only the access token

Make sure you’ve requested the offline scope when initiating the authorization flow.