A grant type simply answers:
βHow is the client proving who the user is to get an access token?β
Different situations β different grant types.
π§ First, the actors
- Resource Owner β User (you)
- Client β App (Angular app, mobile app, backend)
- Auth Server β Keycloak / Okta / Auth0 / Spring Authorization Server
- Resource Server β Your APIs
β 1. Authorization Code Grant (Most Important)
Used when:
User logs in via browser (Angular / React / Web app)
Flow:
- User redirected to Auth Server login page
- User logs in
- Auth server sends code to client
- Client exchanges code for access token
Why this exists?
So that password never touches the client app
Todayβs standard:
π Authorization Code + PKCE (mandatory for SPA)
| Best for | Web apps, SPA, Mobile |
|---|---|
| User present | β |
| Secure | β Most secure |
| Recommended | βββββ |
β 2. Client Credentials Grant
Used when:
Machine-to-Machine communication
No user.
Example:
Order Service β Payment Service
Flow:
Client sends:
client_id + client_secret
Gets access token.
| Best for | Microservice calls |
|---|---|
| User involved | β |
| Secure | β |
| Recommended | βββββ |
You will use this a LOT in microservices.
β 3. Refresh Token Grant
Not for login.
Used to:
Get new access token without asking user to login again
| Best for | Keeping user logged in |
|---|---|
| User involved | β |
| Works with | Authorization Code |
β οΈ 4. Implicit Grant (Deprecated)
Old way for SPA before PKCE existed.
Problems:
- Token in browser URL
- Security issues
β Do not use in 2026
Replaced by:
Authorization Code + PKCE
β οΈ 5. Resource Owner Password Credentials (ROPC) (Deprecated)
Used when:
Client asks user:
βEnter username & password hereβ
Then sends password to auth server.
This is what basic login forms used to do.
Problems:
- Client sees password
- Very insecure
β Not recommended anymore
π§© 6. Device Code Grant
Used when:
Device has no browser
Example:
- Smart TV
- CLI tool
- IoT device
Flow: TV shows code β user enters on phone β TV gets token.
| Best for | TV, CLI, IoT |
|---|---|
| User present | β (on another device) |
π 7. PKCE (Enhancement, not a grant)
PKCE = extra security layer for Authorization Code.
Mandatory for:
- Angular / React SPA
- Mobile apps
Prevents code interception attacks.
π Quick Comparison
| Grant Type | User Login | Where Used | Status |
|---|---|---|---|
| Authorization Code + PKCE | β | Web, SPA, Mobile | β Best |
| Client Credentials | β | Microservices | β Best |
| Refresh Token | β | Session renewal | β |
| Device Code | β | TV / CLI | β |
| Implicit | β | Old SPA | β Deprecated |
| Password (ROPC) | β | Old apps | β Deprecated |
π§ Real World Mapping (your kind of backend system)
| Scenario | Grant |
|---|---|
| Angular app login | Authorization Code + PKCE |
| Service to service call | Client Credentials |
| Keep user logged in | Refresh Token |
| CLI tool login | Device Code |
One-liner memory trick
User in browser? β Auth Code No user? β Client Credentials Need new token? β Refresh No browser? β Device Code
Grant Type (Actual grant_type value) |
Common Name | User Involved | Typical Use Case | Status / Notes |
|---|---|---|---|---|
authorization_code |
Authorization Code | β Yes | Web apps, SPA, Mobile apps (with PKCE) | β Recommended standard |
client_credentials |
Client Credentials | β No | Service-to-service / microservices | β Recommended |
refresh_token |
Refresh Token | β No | Get new access token without login | β Used with auth code |
urn:ietf:params:oauth:grant-type:device_code |
Device Code | β Yes (on another device) | TV, CLI tools, IoT devices | β Recommended for devices |
password |
Resource Owner Password Credentials (ROPC) | β Yes | Legacy apps asking username/password directly | β Deprecated / avoid |
implicit |
Implicit Grant | β Yes | Old browser-based apps | β Deprecated / removed from best practices |
Example Token Requests
Authorization Code
grant_type=authorization_code
Client Credentials
grant_type=client_credentials
Refresh Token
grant_type=refresh_token
Device Code
grant_type=urn:ietf:params:oauth:grant-type:device_code
Password (deprecated)
grant_type=password