APIBeta

Build an OAuth integration

Connect your own integration to Redokun with OAuth, step by step, from client registration to revocation.

This guide is for a development team that wants its integration to call the API as a manager of the team, with OAuth instead of the API key of the team leader. You register your client yourself: you do not need to ask Redokun for anything.

Read OAuth first: it explains who an OAuth connection acts as, and what ends it.

Before you start

  • A manager of the team (or the leader) gives the consent once, in the browser. The integration then acts as that person. See The connection acts as one person.
  • The plan of the team must include the API, and OAuth must be enabled for the team.
  • Your integration needs a redirect URI that the browser of the manager can reach: an https URL on your server, or http://localhost, http://127.0.0.1 or http://[::1] on any port, for a tool that runs on the computer of the manager.
  • The examples use curl, openssl and jq.
EndpointURL
Authorization server metadatahttps://app.redokun.com/.well-known/oauth-authorization-server
Protected resource metadatahttps://api.redokun.com/.well-known/oauth-protected-resource
Registrationhttps://app.redokun.com/oauth/register
Authorizationhttps://app.redokun.com/oauth/authorize
Tokenhttps://app.redokun.com/oauth/token
Revocationhttps://app.redokun.com/oauth/revoke

The metadata documents list the same endpoints. A client that reads them does not need to hard-code the URLs.

1. Register your client

Register once, with Dynamic Client Registration (RFC 7591). The body is JSON:

curl https://app.redokun.com/oauth/register \
  -H "Content-Type: application/json" \
  -d '{
    "client_name": "Acme translation sync",
    "redirect_uris": ["https://sync.acme.example/oauth/callback"]
  }'
{
  "client_id": "3f9c2a7be14d4e0f9a61c8d25b7e0a44",
  "client_id_issued_at": 1764240000,
  "client_name": "Acme translation sync",
  "redirect_uris": ["https://sync.acme.example/oauth/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}

Store the client_id. There is no client secret: every client is a public client, and PKCE protects the code exchange.

FieldRules
client_nameRequired. 1 to 100 characters. The consent page shows it to the manager
redirect_urisRequired. 1 to 10 URIs, 4000 characters at most all together. https, or http on localhost, 127.0.0.1 or [::1]. No fragment, no user or password
logo_uri, client_uriOptional. https only
token_endpoint_auth_methodOptional. Only none
grant_types, response_typesOptional. If you send them, they must contain authorization_code and code

An invalid body gets 400 with the error invalid_client_metadata or invalid_redirect_uri, and an error_description that names the problem.

Registration is limited to 20 calls per minute and 200 per hour per IP address. Over the limit, the answer is 429 with a Retry-After header.

Connect within 30 days

Redokun deletes a client that nobody has connected 30 days after its registration. Once a manager has given the consent, the client stays.

2. Create a PKCE pair

For each authorization, create a random code_verifier and derive its code_challenge with SHA-256 (RFC 7636). Only the S256 method is accepted.

code_verifier=$(openssl rand -base64 60 | tr '+/' '-_' | tr -d '=\n')
code_challenge=$(printf '%s' "$code_verifier" | openssl dgst -sha256 -binary | openssl base64 | tr '+/' '-_' | tr -d '=\n')
state=$(openssl rand -hex 16)

The verifier must have 43 to 128 characters among A-Z, a-z, 0-9, -, ., _ and ~. Keep it, and the state, until the code exchange.

Open this URL in the browser of the manager:

https://app.redokun.com/oauth/authorize
  ?response_type=code
  &client_id=3f9c2a7be14d4e0f9a61c8d25b7e0a44
  &redirect_uri=https%3A%2F%2Fsync.acme.example%2Foauth%2Fcallback
  &code_challenge=<code_challenge>
  &code_challenge_method=S256
  &scope=write
  &state=<state>
  &resource=https%3A%2F%2Fapi.redokun.com
ParameterDescription
response_typeAlways code
client_idFrom step 1
redirect_uriOne of the registered URIs, exactly. Required when the client has more than one. A localhost URI matches any port
code_challenge, code_challenge_methodFrom step 2. The method is always S256
scoperead (calls that read) or write (every call). With no scope, the client asks for write
stateA random value. Check that the redirect carries the same value
resourceOptional. Only https://api.redokun.com

Redokun asks the manager to sign in, then shows the consent page with the name of your client, the access it asks for, the account and the team. The manager can lower write to read, never raise it.

The request waits 10 minutes for the sign-in and the consent. After that, start again from this step.

When the manager clicks Allow, the browser goes to your redirect URI with a code:

https://sync.acme.example/oauth/callback?code=def50200a1b2...&state=<state>

If the manager cancels, or cannot connect (a translator, a team whose plan does not include the API, a subscription that is not active), the redirect carries error=access_denied instead.

A request with an unknown client_id or a redirect_uri that is not registered never redirects: the manager sees an error page.

4. Exchange the code for tokens

The code works once, and only for 60 seconds. Exchange it at once. The token endpoint takes a form body (application/x-www-form-urlencoded), not JSON:

curl https://app.redokun.com/oauth/token \
  -d grant_type=authorization_code \
  -d client_id=3f9c2a7be14d4e0f9a61c8d25b7e0a44 \
  -d code=def50200a1b2... \
  -d redirect_uri=https://sync.acme.example/oauth/callback \
  -d code_verifier="$code_verifier"
{
  "token_type": "Bearer",
  "expires_in": 3600,
  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs...",
  "refresh_token": "def50200f3c4...",
  "scope": "write"
}
TokenLifetimeUse
Access token1 hourCalls to the API
Refresh token30 daysNew tokens at /oauth/token. Each one works once

Read scope in the answer: it is read if the manager lowered the access on the consent page.

Store the refresh token where your integration keeps its secrets: it is the long-lived credential of the connection.

5. Call the API

Send the access token as a bearer token, like an API key:

curl https://api.redokun.com/v1/me \
  -H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIs..."

GET /v1/me returns the account of the manager who gave the consent.

An expired or revoked access token gets 401 with the code UNAUTHENTICATED. See When a call is refused for the other refusals.

6. Refresh the tokens

Before the access token expires, or when a call gets 401, ask for new tokens with the refresh token:

curl https://app.redokun.com/oauth/token \
  -d grant_type=refresh_token \
  -d client_id=3f9c2a7be14d4e0f9a61c8d25b7e0a44 \
  -d refresh_token=def50200f3c4...

The answer has the same fields as in step 4, with a new refresh token. The old refresh token and the old access token stop working at once.

A refresh token works once

If a refresh token that was already used comes back, Redokun revokes the whole connection: every token stops working, and the manager must give the consent again. There is no grace period. Two refreshes in parallel with the same token count as a reuse too.

So:

  • Refresh in one place only. If your integration runs on several workers or processes, one of them refreshes and the others read the tokens it stores. Use a lock around the refresh.
  • Store the new refresh token before you use the new access token. If you lose it, the next refresh fails and the connection is gone.
  • Do not retry a refresh blindly. If the answer is lost (a timeout), a retry with the same token is a reuse.
  • Refresh at least once every 30 days. A refresh token expires after 30 days, and the manager must then give the consent again.

7. Revoke the connection

When the integration stops, or the manager asks to disconnect it, revoke the refresh token (RFC 7009):

curl https://app.redokun.com/oauth/revoke \
  -d client_id=3f9c2a7be14d4e0f9a61c8d25b7e0a44 \
  -d token=def50200f3c4...

The answer is 200 with an empty body.

  • A refresh token revokes the whole connection: every token stops working, and the app leaves the connected apps of the manager.
  • An access token revokes only that access token. The refresh token keeps working.
  • An unknown, expired or already revoked token also gets 200, and changes nothing.

The manager can also disconnect the app in Settings > Integrations > Connected apps, where they see every app they connected.

The connection acts as one person

The connection acts as the manager who gave the consent, not as the team:

  • Every action shows the name of that manager. For example, the documents your integration uploads belong to that manager.
  • When that manager leaves the team, becomes a translator or deletes the account, the connection is revoked and your integration stops. See what ends a connection.
  • The rate limit is per person: all the connections of the manager share one budget.

To keep the integration independent from the people of the team, create a dedicated manager account for it, for example integrations@acme.example, and give the consent with that account. The account uses a seat of the team.

Errors of the OAuth endpoints

The registration, token and revocation endpoints answer errors with an OAuth body, not with the body of the API:

{
  "error": "invalid_grant",
  "error_description": "The connection to this app has been revoked"
}
StatuserrorCause
400invalid_client_metadata, invalid_redirect_uriRegistration: the body is not valid
400invalid_requestA parameter is missing or malformed, the redirect_uri differs from the one of the authorization, or the body is not a form
400invalid_grantThe code is expired, used or for another client; the code_verifier does not match; the refresh token is not valid, expired or already used; the connection is revoked
400invalid_scopeThe scope is not read or write, or is more than the connection allows
400invalid_targetThe resource is not https://api.redokun.com
400unsupported_grant_typeThe grant_type is not authorization_code or refresh_token
401invalid_clientThe client_id is unknown
429too_many_requests, temporarily_unavailableToo many calls. Wait the seconds in Retry-After
500server_errorSomething failed on the Redokun side

When a refresh gets invalid_grant, the connection cannot be repaired: send the manager to the consent page again (step 3).

On this page