Microservice Patterns
Federated Identity and Access Tokens
Delegate sign-in to an identity provider and pass signed access tokens between services, so applications never handle passwords and can verify who the caller is locally — even when the identity provider is briefly down.
What you will learn
- Explain federated identity with OpenID Connect and OAuth 2.0.
- Compare per-request session introspection with locally validated tokens.
- Propagate identity between microservices with access tokens.
- Handle expiry, revocation and key rotation.
Overview
At a festival you show your ID once at the entrance and get a wristband. Every bar and stage checks the wristband, not your passport — and they can do it even if the ticket office is closed.
With federated identity, users sign in at an identity provider (Entra ID, Google, Keycloak, Auth0) via OpenID Connect; your applications never see passwords and get single sign-on for free. The result is an access token — usually a signed JWT with the user id, roles and an expiry. Services verify the signature with the provider's public keys (JWKS), so they do not need to call anyone to know who the caller is.
Run it
The identity provider is unavailable from t = 12 s to 22 s. Compare API calls failed when the API asks the provider on every request (A) and when it validates tokens locally (B).
Validating a caller
| Approach | Per-request cost | Provider outage | Revocation |
|---|---|---|---|
| Session id + introspection call | A network call | Everything fails | Immediate |
| Signed JWT, local verification | A signature check | Only new sign-ins fail | At expiry (keep tokens short-lived) |
| JWT + short cache of introspection | Mostly local | Degrades gradually | Within the cache TTL |
Resource server configuration
spring:
security:
oauth2:
resourceserver:
jwt:
issuer-uri: https://login.example.com/realms/shop # discovers and caches the signing keys
audiences: [ orders-api ]
# Service-to-service: forward the user's token (or exchange it for a narrower one) on outgoing calls,
# so downstream services can authorise the original user, not just "the orders service".Trade-offs
| Benefits | Costs | |
|---|---|---|
| Security | No passwords in your apps; MFA and policies in one place. | The provider is a high-value dependency; tokens must be protected in transit and storage. |
| Availability | Local validation keeps services working through provider blips. | Revoked users keep access until their token expires. |
| Simplicity | Standard protocols and libraries everywhere. | OAuth/OIDC flows are easy to misconfigure — follow current best-practice profiles. |
Production considerations
- Rotate signing keys regularly; services must refresh JWKS when they see an unknown key id.
- Keep tokens small — put identity and coarse roles in them, not every permission.
- Use Authorization Code + PKCE for browser and mobile apps.
- Validate tokens at the gatekeeper and again in each service.