OAuth2Client
A cross-platform OAuth2 client for interacting with an Okta Authorization Server.
This client is storage-agnostic — it handles HTTP calls, token validation, and event emission but never persists tokens. To store tokens, use TokenCredentialManager:
// 1. Create the client
val client = OAuth2ClientBuilder.create(issuerUrl, clientId, scope).getOrThrow()
// 2. Perform a token request (e.g., from a flow class)
val tokenInfo = client.tokenRequest(formParams).getOrThrow()
// 3. Persist via TokenCredentialManager
val tokenData = TokenData(tokenInfo, client.configuration)
val credential = manager.store(tokenData).getOrThrow()Use com.okta.authfoundation.client.OAuth2ClientBuilder to create an instance via the builder pattern.
On Android, the existing OAuth2Client class provides backward-compatible access with additional platform-specific features.
Functions
Performs a device authorization request per RFC 8628.
Resolves OAuth2Endpoints, or throws OAuth2ClientResult.Error.OidcEndpointsNotAvailableException with the original discovery failure attached as its cause.
Performs the OIDC User Info call.
Performs a call to the Authorization Server to validate the specified token per RFC 7662.
Attempt to refresh a token using the provided refresh token string.
Attempt to refresh a token using the provided refresh token string, forwarding additional form body parameters to the token endpoint.
Attempt to revoke the specified token.