The role of the identity-backend

 Great question.

The short answer is:
No, the identity-backend does NOT authorize each request directly.

Let me explain, principal engineer style:


1. What Does identity-backend Do?

  • It authenticates users (verifies their username/password) and issues JWT tokens.

  • It also provides endpoints to:

    • Issue tokens (/token)

    • (Optionally) verify tokens (/verify endpoint, if you call it)

    • Return OIDC metadata for clients

But:
After issuing the JWT, it is NOT in the request path for every user or API call.


2. Who Actually Authorizes?

  • The other services (API Gateway, Worker, Logging, etc.) are responsible for authorization.

  • How?

    • They check the JWT token provided by the client (from session, cookie, or Authorization header).

    • They verify its signature, issuer, audience, and expiry.

    • If the token is valid and unexpired, the request is authorized to proceed.

This is called a "stateless" architecture:

  • The services trust the signed JWT (which can’t be faked if secret is safe).

  • There is no need to call identity-backend for every request—this is why JWTs scale.


3. What About Fine-Grained Authorization?

  • Who does what (e.g., roles, access levels) is usually encoded in JWT claims (scope, roles, etc.).

  • The receiving service (API Gateway, etc.) decides, based on those claims, if the request is allowed.

  • The identity-backend is not consulted in real-time.


4. Is This Good?

Yes, for almost all modern architectures!

  • It offloads the authentication bottleneck.

  • Reduces latency (no round-trip to auth server for every request).

  • Each service must verify JWTs securely (with correct secret or key).


5. What If I Want Central Real-Time Authorization?

  • You’d need an API gateway or middleware that calls the identity service on every request (not common unless you need instant token revocation or auditing).

  • Even then, best practice is: Self-contained JWTs, validated by each service.

  • If you must, you can implement token blacklists or short TTLs, but you’ll rarely want to make identity-backend a bottleneck.


Summary Table

Service Authenticates Users? Issues JWT? Authorizes Each Request? Verifies JWT?
identity-backend Yes Yes No (optional)
API Gateway No No Yes Yes
Worker, Logging No No Yes (if needed) Yes

Bottom Line

  • identity-backend is the authenticator and token issuer—not a request firewall.

  • Your services are the authorizers—they verify tokens for each request.


If you want to see where the authorization happens, look for code that checks or verifies JWTs in your API Gateway and other services—not in identity-backend itself.


Let me know if you want a code walkthrough of how the token check happens in your API Gateway, or how to make it even more robust!

Comments

Popular posts from this blog

Feature: Audit log for one login, and identity service

Getting started - Build your data science lab environment

QA - Run #1 - Results