OAuth2TokenProvider¶
OAuth2TokenProvider ¶
OAuth2TokenProvider(
refresh_token: str,
client_id: str,
token_endpoint_url: str,
token_introspection_url: str,
access_token: str | None = None,
client_secret: str | None = None,
*,
refresh_expiry_threshold_band: timedelta = datetime.timedelta(seconds=5)
)
Provide an OAuth 2.0 token.
Parameters:
-
refresh_token(str) –The refresh token (from the Driverless AI server web UI) used to obtain new access tokens.
-
client_id(str) –The client identifier as assigned by the authorization server.
-
token_endpoint_url(str) –The URL of the authorization server's token endpoint.
-
token_introspection_url(str) –The URL of the authorization server's token introspection endpoint.
-
access_token(str | None, default:None) –The initial access token, if available.
-
client_secret(str | None, default:None) –The client secret, if required for the client credentials.
-
refresh_expiry_threshold_band(timedelta, default:timedelta(seconds=5)) –The time duration before actual expiry when the access token should be refreshed.
Example
# Create a token provider with a refresh token from the Driverless AI web UI
token_provider = driverlessai.token_providers.OAuth2TokenProvider(
refresh_token="eyJhbGciOiJIUzI1N...",
client_id="python_client",
token_endpoint_url="https://keycloak-server/auth/realms/driverlessai/protocol/openid-connect/token",
token_introspection_url="https://keycloak-server/auth/realms/driverlessai/protocol/openid-connect/token/introspect"
)
# Use the token provider to get authorization to connect to the server
client = driverlessai.Client(
address="https://localhost:12345",
token_provider=token_provider.ensure_fresh_token
)
ensure_fresh_token ¶
ensure_fresh_token() -> str
Returns an access token ensuring that it is fresh and valid.
Returns:
-
str–The current access token.