Skip to content
Last updated

Manage OAuth2 clients

Plans:ScaleEnterprise

An OAuth2 client lets an application call the Redocly platform API on behalf of a user of your organization. The application signs the user in with the OAuth 2.0 authorization code flow and calls the API with the access token it receives. You can add OAuth2 clients to your organization and revoke them when you are finished using them.

To call the API from a server without a user, use an API key instead.

Users with the Owner role can add, edit, and revoke OAuth2 clients.

Redocly stores client secrets as one-way cryptographic hashes in the backend. The plaintext value of the secret can't be retrieved.

Add OAuth2 clients

To add an OAuth2 client:

  1. Log in to your Redocly instance.
  2. Select Access > OAuth2 clients in the navigation menu on the left side of the page.
  3. Click New OAuth2 client.
  4. Enter a Name for the client.
  5. (Optional) Enter a Description and upload a Logo. Users see them on the consent screen when they authorize the application.
  6. Enter the Application URL, the home page of your application.
  7. Under Redirect URIs, click Add redirect URI and enter the URL of your application that receives the authorization code. To allow more than one URL, click Add redirect URI again.
  8. Select the Organization permissions and Project permissions that the application needs. For details on the available permissions, see OAuth2 client permissions.
  9. Click Create.
  10. Click the copy icon next to the newly created client secret to save it to your clipboard. Save the secret somewhere safe, as you can't access it again later.

The Client ID column displays the client ID. If you lose the client secret, revoke the client and add a new one.

Verification status

Redocly reviews the OAuth2 clients of each organization. The Verification column displays the result: Unverified, Verified, or Rejected. Your application can use a client that is unverified or verified.

When Redocly rejects a client, the application can't sign users in with it or call the API with its tokens. The Edit OAuth2 client dialog displays the reason for the rejection.

When you change the Application URL of a client, the client returns to Unverified and Redocly reviews it again. This also applies to a rejected client.

OAuth2 client permissions

The permissions you select for a client are the scopes that the application can request. Choose from a list of organization permissions and a list of project permissions. You must select at least one permission.

Each permission has a type that describes the kind of access it grants:

  • Read permissions allow viewing or listing resources.
  • Write permissions allow creating or updating resources.
  • Delete permissions allow removing resources.

Use the Quick select buttons above each list to set permissions in bulk:

  • Full access selects every permission in the list.
  • Read only selects only the read-type permissions in the list.
  • None clears the selection.

An access token never grants more than the user who authorized the application can do. The API accepts a request only when both of the following are true:

  • The token includes the scope that the operation requires.
  • The user has a role that grants the same permission. The user must be a member of your organization.

Organization permissions

You can select the following organization permissions for an OAuth2 client:

PermissionTypeGrants
org.auditLogs.readReadView and export the organization audit logs. Requires the Enterprise plan.
org.organizations.readReadView organization details and settings.
org.organizations.updateWriteUpdate organization details and settings.
org.project.readReadList and view projects in the organization.

Project permissions

You can select the following project permissions for an OAuth2 client:

PermissionTypeGrants
project.feedback.deleteDeleteDelete feedback items in a project.
project.feedback.readReadList, view, and export feedback in a project.
project.feedback.updateWriteUpdate feedback items in a project, such as their status.
project.git.branch.deleteDeleteDelete branches in a project.
project.git.branches.readReadList and view branches in a project.
project.remotes.createWriteCreate project remotes.
project.remotes.deleteDeleteDelete project remotes.
project.remotes.readReadList and view project remotes and their pushes.
project.remotes.updateWriteUpdate project remotes and push files to them.

Edit OAuth2 clients

To change the name, description, logo, URLs, or permissions of an OAuth2 client:

  1. Log in to your Redocly instance.
  2. Select Access > OAuth2 clients in the navigation menu on the left side of the page.
  3. Click More options next to the OAuth2 client you want to change, then click Edit.
  4. Change the details of the client.
  5. Click Save.

Revoke OAuth2 clients

When you are finished using an OAuth2 client, you can revoke the client. The application can't sign users in with a revoked client or call the API with its tokens.

  1. Log in to your Redocly instance.
  2. Select Access > OAuth2 clients in the navigation menu on the left side of the page.
  3. Click More options next to the OAuth2 client you want to revoke, then click Revoke.
  4. Confirm that you want to revoke the client.

Connect your application

Your application uses the following endpoints. If your organization is on app.cloud.eu.redocly.com, use the EU endpoints.

EndpointUSEU
Authorizationhttps://auth.cloud.redocly.com/api/auth/oauth2/authorizehttps://auth.cloud.eu.redocly.com/api/auth/oauth2/authorize
Tokenhttps://auth.cloud.redocly.com/api/auth/oauth2/tokenhttps://auth.cloud.eu.redocly.com/api/auth/oauth2/token

To get an access token for a user:

  1. Redirect the user to the authorization endpoint with the following query parameters:

    • response_type: code
    • client_id: the client ID
    • redirect_uri: one of the redirect URIs of the client
    • scope: the permissions that the application needs, separated by spaces. Add openid and offline_access to receive a refresh token.
    • state: a random value that your application checks when the user returns
    • code_challenge: the Base64URL-encoded SHA-256 hash of a random code_verifier that your application generates for each authorization request, as described in Proof Key for Code Exchange (PKCE)
    • code_challenge_method: S256

    The following example asks for permission to read project feedback and for a refresh token:

    https://auth.cloud.redocly.com/api/auth/oauth2/authorize?response_type=code&client_id=<your-client-id>&redirect_uri=https%3A%2F%2Fdocs-sync.example.com%2Fcallback&scope=openid%20offline_access%20project.feedback.read&state=<random-value>&code_challenge=<code-challenge>&code_challenge_method=S256
    

    After the user signs in to Redocly and approves the requested permissions on the consent screen, Redocly redirects the user to the redirect URI with the authorization code in the code query parameter. When Redocly can't issue the code, for example because the request asks for a permission that the client doesn't have, the redirect URI receives the error query parameter instead.

  2. Send a POST request to the token endpoint to exchange the code for tokens. Send the client ID, the client secret, and the code_verifier in the form-encoded request body. The token endpoint rejects the client ID and the client secret in the Authorization header.

    curl https://auth.cloud.redocly.com/api/auth/oauth2/token \
      --data-urlencode grant_type=authorization_code \
      --data-urlencode code=<authorization-code> \
      --data-urlencode redirect_uri=https://docs-sync.example.com/callback \
      --data-urlencode client_id=<your-client-id> \
      --data-urlencode client_secret=<your-client-secret> \
      --data-urlencode code_verifier=<code-verifier>
    

    The response contains the access_token and, when you asked for openid and offline_access, the refresh_token.

  3. Send the access token in the Authorization header of your API requests:

    Authorization: Bearer <access-token>
    

The Redocly platform API reference lists the operations that accept OAuth 2.0 and the scope that each one requires.

Refresh access tokens

Access tokens expire after two hours. To get a new access token without asking the user to sign in again, send a POST request to the token endpoint with the refresh token:

curl https://auth.cloud.redocly.com/api/auth/oauth2/token \
  --data-urlencode grant_type=refresh_token \
  --data-urlencode refresh_token=<refresh-token> \
  --data-urlencode client_id=<your-client-id> \
  --data-urlencode client_secret=<your-client-secret>

Each response contains a new refresh token. Store it and use it for the next refresh. A refresh token works only once. If your application sends a refresh token that it already used:

  • Within 10 seconds, with the same request, Redocly returns the same response as the first time, for example when your application retries after a network error.
  • After 10 seconds, Redocly revokes all access tokens and refresh tokens of that user for the client, and the user must authorize the application again.

A refresh token expires eight hours after it is issued. If your application doesn't refresh the access token within eight hours, the user must authorize the application again.

Resources