Posts

Showing posts from October, 2024

OAuth Token Propagation Patterns

# OAuth Token Propagation Patterns in Microservices ## 1. Token Relay Pattern ### Description Forwards the original OAuth token through service chains while maintaining the original user context. ### Implementation ```mermaid sequenceDiagram     participant C as Client     participant AG as API Gateway     participant S1 as Service 1     participant S2 as Service 2          C->>AG: Request + OAuth Token     AG->>AG: Validate Token     AG->>S1: Forward Request + Token     S1->>S2: Forward Request + Original Token     S2->>S2: Validate Token ``` ### Considerations - **Pros:**   - Simple implementation   - Maintains user context   - Easy to audit - **Cons:**   - Token size overhead   - Potential scope exposure   - Limited granular control ### Code Example ```java public class TokenRelayInterceptor implements ClientHttpRequestIn...