Overview
COSMIC supports OAuth 2.1 Authorization Code with PKCE. Most integrations follow this flow:Before you begin
Create an app in the developer portal. You will need your app’sclient_id, at least one allowed redirect_uri, and the scopes your app will use.
See Creating apps.
Authorization endpoint
Start the OAuth flow by redirecting the user to:&scope=openid%20email%20profile if you need broader sign-in profile data or an ID token—see scope below.
Query parameters
string
required
Your app’s client identifier from the developer portal.
string
required
The callback URI to redirect the user to after authorization. This must
exactly match one of the allowed redirect URIs configured for your app.
Redirect URIs must match exactly, including scheme, host, path, and trailing
slash. See Redirect URIs.
string
Optional. Space-separated OpenID Connect / OAuth sign-in values for this step only (for example
openid email profile). They do not select COSMIC API permissions—those come from your app in the
developer portal; see Scopes. If you omit scope, COSMIC uses a default suitable for basic sign-in; include openid when you need an ID token in the token response.string
required
Must be
code.string
required
The Base64URL-encoded SHA-256 hash of your app’s
code_verifier.string
required
Must be
S256.string
A client-generated value used to prevent
CSRF.
Generate a unique value per request and verify it on callback.
User consent and redirect
After the user signs in and approves the request, COSMIC redirects the browser to your registeredredirect_uri.
Example:
- verify that
statematches the value you originally sent - extract the authorization
code - exchange that code at the token endpoint
Token endpoint
Exchange the authorization code at:Authorization code exchange parameters
string
required
Must be
authorization_code.string
required
The authorization code returned to your
redirect_uri.string
required
The same
redirect_uri used in the authorization request.string
required
Your app’s client identifier.
string
required
The original random secret generated by your app for this authorization
request.
- Public client
- Confidential client
Send the token request without a
client_secret.Token response
A successful response returns OAuth tokens, including an access token and, when applicable, a refresh token.string
The access token used to call COSMIC APIs.
string
The token type. Typically
Bearer.integer
The lifetime of the access token in seconds.
string
A refresh token that can be used to obtain a new access token, when
applicable.
string
Space-delimited sign-in / identity scopes for this authorization (from your authorize request, or COSMIC defaults). This is separate from COSMIC API scopes on the token; see Scopes and Access tokens.
After you receive a token
Use the access token as a Bearer credential on API requests. See Access tokens forGET /v1/me, scopes on the token, and how to list organizations and members.
If a call returns 403, common causes include:
- the token does not include the scope required for that endpoint
- the app cannot access that organization or member in the current context
- an organization admin must re-approve the app in COSMIC after you add or widen scopes in the developer portal
Refresh tokens
To obtain a new access token, send a refresh token to the same token endpoint:Refresh token parameters
string
required
Must be
refresh_token.string
required
The refresh token previously issued to your app.
string
Your app’s client identifier, if required by your app’s configured token
endpoint authentication method.
- Public client
- Confidential client
Send the refresh token request without a
client_secret.Common errors
redirect_uri mismatch
The redirect_uri sent in the authorization request and token request must exactly match a URI registered for the client.
This includes:
- scheme
- host
- path
- trailing slash
invalid_grant
Common causes include:
- the authorization code expired
- the authorization code was already used
- the
code_verifierdoes not match the original PKCE challenge - the
redirect_uridoes not match the original authorization request
state mismatch
If you send state, verify it on callback. Reject the response if the returned value does not match the original value stored by your app.

