Class OAuth2ClientCredentialsGrantCredentialsProvider

All Implemented Interfaces:
CredentialsProvider

public class OAuth2ClientCredentialsGrantCredentialsProvider extends RefreshProtectedCredentialsProvider<OAuth2ClientCredentialsGrantCredentialsProvider.Token>
A CredentialsProvider that performs an OAuth 2 Client Credentials flow to retrieve a token.

The provider has different parameters to set, e.g. the token endpoint URI of the OAuth server to request, the client ID, the client secret, the grant type, etc. The OAuth2ClientCredentialsGrantCredentialsProvider.OAuth2ClientCredentialsGrantCredentialsProviderBuilder class is the preferred way to create an instance of the provider.

The implementation uses the JDK HttpURLConnection API to request the OAuth server. This can be easily changed by overriding the retrieveToken() method.

This class expects a JSON document as a response and needs Jackson to deserialize the response into a OAuth2ClientCredentialsGrantCredentialsProvider.Token. This can be changed by overriding the parseToken(String) method.

TLS is supported by providing a HTTPS URI and setting a SSLContext. See OAuth2ClientCredentialsGrantCredentialsProvider.OAuth2ClientCredentialsGrantCredentialsProviderBuilder.tls() for more information. Applications in production should always use HTTPS to retrieve tokens.

If more customization is needed, a connectionConfigurator callback can be provided to configure the connection.

See Also: