Class OAuth2ClientCredentialsProvider

java.lang.Object
org.cibseven.bpm.client.interceptor.auth.OAuth2ClientCredentialsProvider
All Implemented Interfaces:
Closeable, AutoCloseable, ClientRequestInterceptor

public class OAuth2ClientCredentialsProvider extends Object implements ClientRequestInterceptor, Closeable

Provides OAuth2 client credentials flow authentication by using the request interceptor api.

Acquires a Bearer access token from the configured token endpoint and sets it as the Authorization: Bearer header on every outgoing request. Tokens are cached in memory and refreshed automatically before they expire.

Two client authentication modes are supported:

Usage:


 ClientRequestInterceptor oauth2 = OAuth2ClientCredentialsProvider.builder()
   .tokenUri("https://idp.example.com/token")
   .clientId("my-client")
   .clientSecret("my-secret")
   .scope("engine-rest/.default")     // optional
   .build();

 ExternalTaskClient client = ExternalTaskClient.create()
   .baseUrl("http://localhost:8080/engine-rest")
   .addInterceptor(oauth2)
   .build();