Package io.unitycatalog.client.auth
Interface TokenProvider
public interface TokenProvider
Interface for providing access tokens to authenticate with Unity Catalog.
Implementations include:
StaticTokenProvider- uses a pre-configured static tokenOAuthTokenProvider- obtains tokens via OAuth 2.0 client credentials flow
-
Method Summary
Modifier and TypeMethodDescriptionReturns the access token for Unity Catalog authentication.configs()Returns the configuration associated with this token provider.static TokenProviderCreates a token provider from a configuration map.voidinitialize(Map<String, String> configs) Initializes the token provider with configuration parameters.
-
Method Details
-
initialize
Initializes the token provider with configuration parameters.- Parameters:
configs- configuration map with authentication settings- Throws:
IllegalArgumentException- if required parameters are missing or invalid
-
accessToken
String accessToken()Returns the access token for Unity Catalog authentication.- Returns:
- the access token string
-
configs
Returns the configuration associated with this token provider.The returned configuration map can be passed to
create(Map)to create a new token provider instance with the same configuration:TokenProvider existingProvider = ...; TokenProvider newProvider = TokenProvider.create(existingProvider.configs());- Returns:
- a map of configuration key-value pairs
-
create
Creates a token provider from a configuration map.This method creates a token provider based on the required
"type"configuration parameter. It supports three authentication modes:- Static token authentication: Set
"type"to"static"and provide a"token"key with the access token value - OAuth 2.0 authentication: Set
"type"to"oauth"and provide all three OAuth keys:"oauth.uri","oauth.clientId", and"oauth.clientSecret" - Custom authentication: Set
"type"to the fully qualified class name of a customTokenProviderimplementation
Example usage with static token:
Map<String, String> configs = new HashMap<>(); configs.put("type", "static"); configs.put("token", "my-access-token"); TokenProvider provider = TokenProvider.create(configs);Example usage with OAuth 2.0:
Map<String, String> configs = new HashMap<>(); configs.put("type", "oauth"); configs.put("oauth.uri", "https://uc.example.com/token"); configs.put("oauth.clientId", "my-client-id"); configs.put("oauth.clientSecret", "my-client-secret"); TokenProvider provider = TokenProvider.create(configs);Example usage with custom token provider:
Map<String, String> configs = new HashMap<>(); configs.put("type", "com.example.MyCustomTokenProvider"); // Add any additional configs required by your custom provider TokenProvider provider = TokenProvider.create(configs);You can also use
configs()to obtain the configuration from an existing token provider and pass it to this method to create a new instance:TokenProvider existingProvider = ...; TokenProvider newProvider = TokenProvider.create(existingProvider.getConfigs());- Parameters:
configs- a map containing authentication configuration parameters. Must contain a non-null, non-empty"type"key.- Returns:
- a token provider configured according to the provided parameters
- Throws:
IllegalArgumentException- if the"type"parameter is null, empty, or if required authentication parameters for the specified type are missing or invalidRuntimeException- if a custom TokenProvider class cannot be instantiated (e.g., class not found, no default constructor, or instantiation failure)
- Static token authentication: Set
-