Use the Authorization Code flow for user-facing applications where an operator grants consent. This flow provides both access and refresh tokens.
- Authorization Request: Redirect the user to the authorization endpoint. Use a cryptographically strong
state value to prevent CSRF attacks. - Token Exchange: After the user consents and is redirected back to your URI, exchange the authorization code for tokens via a POST request to the token endpoint.
# 1. Authorization URL
# https://{organization}.krebit.se/oauth/authorize?client_id={client_id}&redirect_uri={redirect_uri}&response_type=code&state={state}
# 2. Exchange code for tokens
curl --request POST \
--url https://{organization}.krebit.se/api/oauth/token \
--header 'Content-Type: application/json' \
--data '{
"grant_type": "authorization_code",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"redirect_uri": "https://yourapp.example.com/oauth/callback",
"code": "AUTH_CODE_FROM_CALLBACK"
}'