Package io.openlineage.client.transports
Class JwtTokenProvider
java.lang.Object
io.openlineage.client.transports.JwtTokenProvider
- All Implemented Interfaces:
TokenProvider
TokenProvider that exchanges an API key for a JWT token via a POST endpoint.
Sends the API key and OAuth parameters as URL-encoded form data.
The provider automatically tries multiple common JSON field names for the token: the configured tokenFields (default ["token", "access_token"]). This ensures compatibility with various OAuth providers.
The provider caches tokens and automatically refreshes them before expiry. By default, tokens are refreshed 120 seconds before they expire. This can be configured using the tokenRefreshBuffer parameter.
Configuration example:
transport:
type: http
url: https://api.example.com
auth:
type: jwt
apiKey: your-api-key
tokenEndpoint: https://auth.example.com/token
tokenFields: ["token", "access_token"] # optional, defaults to ["token", "access_token"]
expiresInField: expires_in # optional, defaults to "expires_in"
grantType: urn:ietf:params:oauth:grant-type:jwt-bearer # optional, defaults to "urn:ietf:params:oauth:grant-type:jwt-bearer"
responseType: token # optional, defaults to "token"
tokenRefreshBuffer: 120 # optional, defaults to 120 seconds
For IBM Cloud IAM, use these settings:
auth:
type: jwt
apiKey: your-ibm-api-key
tokenEndpoint: https://iam.cloud.ibm.com/identity/token
grantType: urn:ibm:params:oauth:grant-type:apikey
responseType: cloud_iam
-
Constructor Summary
ConstructorsConstructorDescriptionJwtTokenProvider(String apiKey, URI tokenEndpoint) Constructor that requires mandatory parameters apiKey and tokenEndpoint. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.hc.client5.http.impl.classic.CloseableHttpClientCreates an HTTP client for token requests.protected longGets current time in epoch seconds.The JSON field name containing the token expiration time in seconds.OAuth grant type parameter sent in the token request.OAuth response type parameter sent in the token request.getToken()String[]The JSON field name containing the JWT token in the response.intNumber of seconds before token expiry to trigger a refresh.voidsetExpiresInField(String expiresInField) The JSON field name containing the token expiration time in seconds.voidsetGrantType(String grantType) OAuth grant type parameter sent in the token request.voidsetResponseType(String responseType) OAuth response type parameter sent in the token request.voidsetTokenFields(String[] tokenFields) The JSON field name containing the JWT token in the response.voidsetTokenRefreshBuffer(int tokenRefreshBuffer) Number of seconds before token expiry to trigger a refresh.toString()
-
Constructor Details
-
JwtTokenProvider
Constructor that requires mandatory parameters apiKey and tokenEndpoint. Used by Jackson for deserialization.- Parameters:
apiKey- The API key for authentication (required)tokenEndpoint- The token endpoint URI (required)- Throws:
IllegalArgumentException- if apiKey is null/empty or tokenEndpoint is null
-
-
Method Details
-
getToken
- Specified by:
getTokenin interfaceTokenProvider
-
getCurrentTimeSeconds
protected long getCurrentTimeSeconds()Gets current time in epoch seconds. Protected to allow test overrides. -
createHttpClient
protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient createHttpClient()Creates an HTTP client for token requests. Protected to allow test overrides. -
toString
-
getApiKey
-
getTokenEndpoint
-
getTokenFields
The JSON field name containing the JWT token in the response. Defaults to "access_token". The provider will also try "token" and "access_token" as fallback options. -
setTokenFields
The JSON field name containing the JWT token in the response. Defaults to "access_token". The provider will also try "token" and "access_token" as fallback options. -
getExpiresInField
The JSON field name containing the token expiration time in seconds. Defaults to "expires_in". If not present in response, token will be refreshed on every call. -
setExpiresInField
The JSON field name containing the token expiration time in seconds. Defaults to "expires_in". If not present in response, token will be refreshed on every call. -
getGrantType
OAuth grant type parameter sent in the token request. Optional, default: "urn:ietf:params:oauth:grant-type:jwt-bearer" -
setGrantType
OAuth grant type parameter sent in the token request. Optional, default: "urn:ietf:params:oauth:grant-type:jwt-bearer" -
getResponseType
OAuth response type parameter sent in the token request. Optional, default: "token" -
setResponseType
OAuth response type parameter sent in the token request. Optional, default: "token" -
getTokenRefreshBuffer
public int getTokenRefreshBuffer()Number of seconds before token expiry to trigger a refresh. Optional, default: 120 seconds. This buffer ensures tokens are refreshed before they expire to avoid authentication failures. -
setTokenRefreshBuffer
public void setTokenRefreshBuffer(int tokenRefreshBuffer) Number of seconds before token expiry to trigger a refresh. Optional, default: 120 seconds. This buffer ensures tokens are refreshed before they expire to avoid authentication failures.
-