Authorization Code

The authorization code grant is used when an application exchanges an authorization code for an access token.

Overview

This flow is for web applications with a server-side component that can securely store the client secret.

Flow Diagram

spinner

Authorization Request

GET /authorize

Redirect the user to the authorization endpoint.

Parameters

Parameter
Required
Description

response_type

Yes

Must be code

client_id

Yes

Your client identifier

redirect_uri

Yes

URL to redirect after authorization

scope

Yes

Space-separated scopes

state

Recommended

CSRF protection token

Example

Response

User is redirected to redirect_uri with:

circle-info

Always verify the state parameter matches what you sent to prevent CSRF attacks.

Token Request

POST /token

Exchange the authorization code for tokens.

Headers

Header
Value

Content-Type

application/x-www-form-urlencoded

Authorization

Basic {base64(client_id:client_secret)}

Parameters

Parameter
Required
Description

grant_type

Yes

Must be authorization_code

code

Yes

The authorization code

redirect_uri

Yes

Same as authorization request

Example

Response

Complete Example

Node.js

Python

Security Considerations

  1. Always validate state - Prevents CSRF attacks

  2. Use HTTPS - Never transmit tokens over HTTP

  3. Store secrets securely - Never expose client_secret

  4. Validate redirect_uri - Use exact match

  5. Short-lived codes - Authorization codes expire quickly

Next Steps

Last updated

Was this helpful?