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:
- Client secret (
client_secret_post): provide aclientSecret - Client assertion JWT (
private_key_jwt): provide aClientAssertionProvider, e.g.JjwtClientAssertionProviderfor RSA/EC key signing orAzureWorkloadIdentityAssertionProviderfor Azure Workload Identity federated tokens
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();
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected final Stringprotected Stringprotected final ClientAssertionProviderprotected final Stringprotected final Stringprotected final Durationprotected static final Stringprotected final org.apache.hc.client5.http.impl.classic.CloseableHttpClientprotected static final ExternalTaskClientLoggerprotected final com.fasterxml.jackson.databind.ObjectMapperprotected final Stringprotected final Stringprotected Instantprotected final String -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected -
Method Summary
Modifier and TypeMethodDescriptionbuilder()voidclose()protected voidprotected Stringvoidintercept(ClientRequestContext requestContext) Gets invoked before a request is sent to the http server
-
Field Details
-
LOG
-
GRANT_TYPE_CLIENT_CREDENTIALS
- See Also:
-
ASSERTION_TYPE
- See Also:
-
tokenUri
-
clientId
-
clientSecret
-
clientAssertionProvider
-
scope
-
audience
-
resource
-
additionalParameters
-
expiryBuffer
-
httpClient
protected final org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient -
objectMapper
protected final com.fasterxml.jackson.databind.ObjectMapper objectMapper -
cachedToken
-
tokenExpiry
-
-
Constructor Details
-
OAuth2ClientCredentialsProvider
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
builder
-
intercept
Description copied from interface:ClientRequestInterceptorGets invoked before a request is sent to the http server- Specified by:
interceptin interfaceClientRequestInterceptor- Parameters:
requestContext- provides the data of the request and offers methods to change it
-
getValidToken
-
fetchAndCacheToken
protected void fetchAndCacheToken()
-