Skip to main content
Sourcebot supports OAuth 2.0 for apps that call Sourcebot on behalf of a Sourcebot user. Use it when you are building an integration where each user signs in with their own Sourcebot account, instead of sharing one API key. Sourcebot uses the authorization code grant with PKCE and issues refresh tokens. Every request made with an access token acts as the user who approved it, with the same role and permissions. When permission syncing is configured, the app only sees repositories that user can access. In the examples below, replace https://your-sourcebot-instance.com with the URL of your Sourcebot deployment.

Register an OAuth application

Register your app with dynamic client registration. Registration does not need authentication. Do it once and store the returned client_id.
The client_name and logo_uri are shown to users on the consent screen.
Sourcebot does not issue client secrets. Every client is a public client and proves its identity with PKCE. Wildcard redirect URIs are not allowed.

Redirect the user to Sourcebot

Send the user’s browser to the authorization endpoint. If they are not signed in, Sourcebot asks them to sign in first. They then approve or deny your app on the consent screen.
Do not send a scope parameter. Sourcebot does not define any scopes yet, and a request with a scope fails with invalid_scope.

Example

Handle the redirect

When the user approves, Sourcebot redirects to your redirect_uri with a code and the state you sent. Always check that state matches the value you sent before you continue.
If the user denies access, the redirect carries an error instead:
The authorization code can be used once and expires after 10 minutes.

Exchange the code for tokens

Exchange the code and the PKCE code_verifier for an access token and a refresh token.

Example

Response

Make API requests

Send the access token as a Bearer token in the Authorization header, the same way you would send an API key. Access tokens work with the public API and the MCP server. The scoped access token endpoints are the exception and require an API key.

Refresh an access token

When the access token expires, exchange the refresh token for a new access token.
The response has the same shape as the code exchange, including a new refresh_token.
Refresh tokens rotate. Each refresh returns a new refresh token and invalidates the one you sent, so store the new one before you use it. Sending an old refresh token fails with invalid_grant, and the user has to authorize your app again. If several processes share a token, make sure only one refreshes it at a time.

Revoke a token

Revoke a token when the user disconnects your app. Revoking an access token does not revoke its refresh token, so revoke both. Revoking the current pair does not revoke access tokens issued before the most recent refresh. Those tokens remain valid until they expire.
The endpoint always returns 200, even if the token does not exist. Users can also see and disconnect authorized apps in Settings → MCP → Connected clients.

Token lifetimes

Administrators can change these with environment variables.

Discovery

Sourcebot publishes authorization server metadata (RFC 8414) at /.well-known/oauth-authorization-server. Clients that support discovery can read the endpoint URLs from it instead of hard-coding them.