Add a “Connect to Corteksa” button with OAuth 2.0
For an app published to many clients, use the authorization code flow with PKCE: the client approves on the permissions screen, and you exchange the code for an access token that starts with crtk_oauth_ and a refresh token.
Before you start · 1 thing · for ownersYour app registered with the Corteksa team
- Your app registered with the Corteksa team: its name, redirect URIs, allowed scopes and client type. You get a
client_idthat starts withcrtk_app_, and a secret for apps with a server.
Steps
https://{HOST}/en/oauth/authorize with client_id, redirect_uri, scope, state and response_type=code, plus code_challenge with code_challenge_method=S256 for public clients.?code=...&state=..., or ?error=access_denied.state.POST https://{HOST}/api/v1/oauth/token with grant_type=authorization_code, code, redirect_uri, client_id, and client_secret or code_verifier.access_token, refresh_token, expires_in and scope.Authorization: Bearer crtk_oauth_....grant_type=refresh_token, and save the new refresh token every time.Don’t call the token endpoint from the browser, and don’t put client_secret or any crtk_oauth_ token in front-end code.
The 2 client types
client_secretThe rules
The redirect URI matches the registered one exactly. The code is used once, within 60 seconds. The granted scopes are within the requested ones, the requested ones are within what the app is allowed, and all of them are within the user’s live permissions.
Wildcard scopes such as read.* cover every unit the user can reach, so your app can choose any unit to sync without registering again.
Revoking
Revoke from your server with POST /api/v1/oauth/revoke, sending token, client_id and client_secret. Or the client disconnects your app as in Authorize or disconnect a third-party app, and the tokens stop straight away.
If something goes wrong
client_id is unknown, the redirect URI doesn’t match, a scope isn’t allowed, or PKCE is missing.invalid_grant: code is invalid, expired, or already usedinvalid_grant: redirect_uri mismatchinvalid_client