Authorization Server: phát hành và quản lý tokens (identity provider).
- Trong Spring ecosystem dùng
spring-authorization-serverlibrary. - Chịu trách nhiệm: xác thực user, phát JWT, quản lý refresh token, revocation.
- Resource Server: bảo vệ API bằng cách validate token — chỉ xử lý request có token hợp lệ.
- Config Spring Security 6:
http.oauth2ResourceServer(oauth2 -> oauth2.jwt(...)). - Validate: verify chữ ký JWT bằng public key của auth server (lấy từ JWKS endpoint).
- Một Authorization Server có thể phục vụ nhiều Resource Server.
- Trong microservices thực tế: thường dùng Auth Server từ bên thứ ba (Keycloak, Auth0, Okta) thay vì tự build — tránh tái phát minh bánh xe với security phức tạp.