Going deep into OAuth 2.0: the four main roles of resource owner, client, authorization server, and resource server, the endpoint and token components, and all the grant types with when to use them.

Episode 3 dissected the Keycloak architecture. Episode 4 starts diving into the protocol you'll use most often: OAuth 2.0. You'll understand the four roles always involved, the endpoint and token components, all the grant types and when to use them, and the security considerations you must keep in mind. This material is the foundation for episode 5, which breaks down the Authorization Code flow step by step.
OAuth 2.0 defines four cooperating roles:
| Role | Who | Task |
|---|---|---|
| Resource Owner | User | Owner of the resource; approves or denies access |
| Client | Application | Requests access on behalf of the resource owner |
| Authorization Server | Keycloak | Validates identity and issues tokens |
| Resource Server | API | Provides the resource; validates access tokens |
Tip
An easy way to remember: the resource owner is the owner, the client is the permission requester, the authorization server is the permission issuer, and the resource server is the resource keeper. All four are involved in almost every OAuth 2.0 flow.
It's important to understand the boundaries of these roles. The resource owner is almost always a human user. The client can be a web app, a mobile app, or even a backend service acting on its own behalf. The authorization server in our context is Keycloak. The resource server is the API that stores the data you want to access.
OAuth 2.0 defines several components that serve as the contact points of the flow:
/realms/{realm}/protocol/openid-connect/token.openid, profile, and email.Here's an example response from the token endpoint:
{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJidWRpIiwiYXVkIjoicG9ydGFsLWFwcCJ9...",
"expires_in": 300,
"refresh_expires_in": 1800,
"refresh_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJidWRpIiwiZXhwIjoyMzQ1Njc4OTB9...",
"token_type": "Bearer"
}Notice expires_in: access tokens are short-lived (300 seconds in the example), while refresh_token has a longer lifetime. This design is intentional — short-lived tokens minimize the damage if they leak.
OAuth 2.0 defines several ways (grant types) to obtain a token, each suited to a context:
| Grant Type | Context | User Involvement | Status |
|---|---|---|---|
| Authorization Code | Server-side web app | Yes, via browser | Recommended |
| Implicit | Legacy SPA | Yes | Deprecated |
| Password (ROPC) | Trusted client | Yes, password sent | Limited, not recommended |
| Client Credentials | Service-to-service (M2M) | No | Recommended for M2M |
| Device Code | Devices without a browser (TV, IoT) | Yes, via another device | For constrained devices |
| Refresh Token | Refreshing an access token | No | Supporting mechanism |
Four considerations narrow down the choice:
A rule of thumb: when in doubt, choose Authorization Code + PKCE. It's the safest combination for almost any case with a user.
Keycloak maps OAuth 2.0 roles to real configuration:
public or confidential.openid, profile, and email.These are the points you'll visit often in the admin console when implementing grant types in episode 5 and beyond.
Four security practices that must be part of every OAuth 2.0 implementation:
A sentence that summarizes all the considerations above: treat tokens like physical keys. Keys aren't left out in the open, aren't given to strangers, and are replaced if ever lost. State and PKCE ensure tokens reach only the right hands, while secure storage keeps tokens in place.
Episode 4 laid the OAuth 2.0 foundation: the four roles, the authorization and token endpoint components, all the grant types, and security considerations. You now know where Keycloak's token endpoint lives and the shape of token responses you'll encounter often.
Key takeaways:
In the next episode (episode 5), you'll dissect the Authorization Code flow in detail — from the authorization request, user login, the code, token exchange, to PKCE.