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.
To add an OAuth2 client:
- Log in to your Redocly instance.
- Select Access > OAuth2 clients in the navigation menu on the left side of the page.
- Click New OAuth2 client.
- Enter a Name for the client.
- (Optional) Enter a Description and upload a Logo. Users see them on the consent screen when they authorize the application.
- Enter the Application URL, the home page of your application.
- 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.
- Select the Organization permissions and Project permissions that the application needs. For details on the available permissions, see OAuth2 client permissions.
- Click Create.
- 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.
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.
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.
You can select the following organization permissions for an OAuth2 client:
| Permission | Type | Grants |
|---|---|---|
org.auditLogs.read | Read | View and export the organization audit logs. Requires the Enterprise plan. |
org.organizations.read | Read | View organization details and settings. |
org.organizations.update | Write | Update organization details and settings. |
org.project.read | Read | List and view projects in the organization. |
You can select the following project permissions for an OAuth2 client:
| Permission | Type | Grants |
|---|---|---|
project.feedback.delete | Delete | Delete feedback items in a project. |
project.feedback.read | Read | List, view, and export feedback in a project. |
project.feedback.update | Write | Update feedback items in a project, such as their status. |
project.git.branch.delete | Delete | Delete branches in a project. |
project.git.branches.read | Read | List and view branches in a project. |
project.remotes.create | Write | Create project remotes. |
project.remotes.delete | Delete | Delete project remotes. |
project.remotes.read | Read | List and view project remotes and their pushes. |
project.remotes.update | Write | Update project remotes and push files to them. |
To change the name, description, logo, URLs, or permissions of an OAuth2 client:
- Log in to your Redocly instance.
- Select Access > OAuth2 clients in the navigation menu on the left side of the page.
- Click More options next to the OAuth2 client you want to change, then click Edit.
- Change the details of the client.
- Click Save.
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.
- Log in to your Redocly instance.
- Select Access > OAuth2 clients in the navigation menu on the left side of the page.
- Click More options next to the OAuth2 client you want to revoke, then click Revoke.
- Confirm that you want to revoke the client.
Your application uses the following endpoints. If your organization is on app.cloud.eu.redocly.com, use the EU endpoints.
| Endpoint | US | EU |
|---|---|---|
| Authorization | https://auth.cloud.redocly.com/api/auth/oauth2/authorize | https://auth.cloud.eu.redocly.com/api/auth/oauth2/authorize |
| Token | https://auth.cloud.redocly.com/api/auth/oauth2/token | https://auth.cloud.eu.redocly.com/api/auth/oauth2/token |
To get an access token for a user:
Redirect the user to the authorization endpoint with the following query parameters:
response_type:codeclient_id: the client IDredirect_uri: one of the redirect URIs of the clientscope: the permissions that the application needs, separated by spaces. Addopenidandoffline_accessto receive a refresh token.state: a random value that your application checks when the user returnscode_challenge: the Base64URL-encoded SHA-256 hash of a randomcode_verifierthat 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=S256After 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
codequery 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 theerrorquery parameter instead.Send a
POSTrequest to the token endpoint to exchange the code for tokens. Send the client ID, the client secret, and thecode_verifierin the form-encoded request body. The token endpoint rejects the client ID and the client secret in theAuthorizationheader.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_tokenand, when you asked foropenidandoffline_access, therefresh_token.Send the access token in the
Authorizationheader 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.
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.
- Redocly platform API reference - Look up the operations that accept OAuth 2.0 and the scopes each one requires
- Manage API keys - Create API keys for server-to-server calls that don't act on behalf of a user
- Roles and permissions - Explore the user roles that limit what an application can do on behalf of a user