Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 37 ยท Authorization Services

Authorization Services Concepts

Understand Keycloak Authorization Services: resource servers, resources, scopes, policies and permissions, and how they differ from simple role checks.

Authentication answers "who are you?". Authorization answers "what may you do?". Most apps start with roles: a token says admin or editor and the code checks it. That works until rules get specific: "editors may edit only articles in their own department, and only on weekdays". Hard-coding that in every service becomes a mess. Keycloak Authorization Services moves such fine-grained rules into Keycloak so they are defined once, managed in the admin console, and evaluated centrally.

Authorization Services cannot be run on this site. Steps describe the admin console of recent Keycloak versions. The JavaScript samples are stand-ins that evaluate the same kinds of rules so you can see how the pieces combine.

Turning it on

Authorization Services belong to a client. Open the client's Settings and enable Client authentication (the client must be confidential) and Authorization. A new Authorization tab appears. That client now acts as a resource server: the application or API whose resources you protect. The tab contains Settings, Resources, Authorization scopes, Policies, Permissions, and Evaluate.

The building blocks

Authorization Services use four ideas that combine into a decision.

Resource: something to protect. It can be a single object type (Article), a URL pattern (/articles/*), or one instance (/articles/42). Each has a name, an optional type, URIs, owner, and scopes.

Scope: an action on a resource, such as view, edit, delete, or approve. Scopes can be attached to resources.

Policy: a rule that answers "is this caller allowed?" without knowing which resource is involved. Examples: "has role editor", "is a member of group finance", "request is between 09:00 and 17:00", "is user ana", "comes from client mobile-app".

Permission: the glue. A permission says "to access resource R (or scope S of R), the caller must satisfy policies P1, P2...". Permissions are either resource-based (apply to a resource or resource type) or scope-based (apply to scopes of resources).

flowchart LR
  P1["Policy: role editor"] --> M["Permission: edit articles"]
  P2["Policy: weekday hours"] --> M
  M --> R["Resource: Article"]
  M --> S["Scope: edit"]

Policies are reusable; permissions attach policies to resources and scopes.

This separation is why the model scales. One policy ("is finance staff") can be reused by dozens of permissions, and changing it updates them all.

Four building blocks

Resource What you protect
Scope An action on it
Policy A reusable rule
Permission Links rules to things

A decision combines all four.

1 / 2

A first model in code

Before looking at the console, model the idea in plain JavaScript. This stand-in has resources, scopes, role policies, and permissions, and answers "may this user do this?":

JS Stand-in: resources, scopes, policies, permissions

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice the last case: with no permission for approve, the default result is deny. Keycloak behaves the same way: a resource with no matching permission is not accessible.

How decisions are requested

A client (typically a resource server) can ask Keycloak for a decision in several ways:

  • With UMA-style token requests: the app sends an access token and asks the token endpoint with grant_type=urn:ietf:params:oauth:grant-type:uma-ticket and an audience set to the resource server client. The answer is a requesting party token (RPT) that carries a permissions list.
  • With response_mode=decision: the endpoint returns only {"result": true} or a 403, useful for simple yes/no checks.
  • With response_mode=permissions: the endpoint lists the granted resources and scopes without issuing a token.
  • With a policy enforcer library embedded in the app that does the requests and caching for you.

The RPT and enforcement lesson covers these calls in depth.

Authorization versus plain roles

Question Roles in tokens Authorization Services
Is the rule simple, coarse (admin, user)? Perfect fit Overkill
Must rules depend on the specific resource? Awkward Natural
Should non-developers change rules? Needs a deploy Admin console
Do rules combine time, group, owner? Custom code Built-in policy types
Token size and performance Small tokens Extra request per decision (cache it)

A good rule: start with roles and groups. Add Authorization Services when role explosion appears (article-editor-sales, article-editor-hr, ...) or when the app itself manages permissions per resource, such as sharing a document with a colleague.

The Evaluate tab

On the client's Authorization tab, Evaluate lets you pick a user, roles, a resource and scopes, then shows which permissions and policies grant or deny. It is the first place to look when a decision surprises you, and works without any application code.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which client type can act as a resource server for Authorization Services?

    Enable client authentication (confidential) and the Authorization switch on the client.
  2. 2. What does a permission do?

    Permissions bind resources and scopes to policies; policies hold the actual rules.
  3. 3. A resource has no permission covering a scope. What is the default outcome?

    Without a matching permission, nothing grants access, so the decision is deny.
  4. 4. When is plain role checking usually enough?

    Roles are simple, small, and fast; reach for Authorization Services when per-resource rules appear.

Summary

  • Authorization Services add fine-grained, centrally managed access rules to a client that acts as a resource server.
  • Resources are what you protect, scopes are actions, policies are rules, permissions link them.
  • Decisions default to deny without matching permissions.
  • Use the Evaluate tab to test rules.
  • Prefer roles for coarse rules; use Authorization Services when rules depend on the resource.

Next: Policies, Permissions, and Decision Strategies