OAuthConfig

data class OAuthConfig(val accessToken: String, val refreshToken: String, val clientId: String, val clientSecret: String, val tokenUrl: String = TOKEN_URL, val onTokensRefreshed: (accessToken: String, refreshToken: String) -> Unit? = null)(source)

OAuth2 authentication configuration for the Volvo ID identity system.

Handles the complete OAuth2 Bearer token lifecycle including automatic refresh. When the access token expires (401 response), the client automatically requests a new one from the Volvo ID token endpoint using the refresh token.

Refresh token rotation: Volvo ID returns a new refresh token with each refresh. The old refresh token is immediately invalidated. Use onTokensRefreshed to persist the new tokens so they survive app restarts.

Token lifecycle:

  • Access tokens are short-lived (typically minutes)

  • Refresh tokens expire after 7 days of inactivity

  • Maximum grant lifetime is 6 months with continuous refreshing

  • After 6 months the user must re-authenticate

val auth = OAuthConfig(
accessToken = storedAccessToken,
refreshToken = storedRefreshToken,
clientId = "your-client-id",
clientSecret = "your-client-secret",
onTokensRefreshed = { newAccess, newRefresh ->
storage.save(newAccess, newRefresh)
}
)

Constructors

Link copied to clipboard
constructor(accessToken: String, refreshToken: String, clientId: String, clientSecret: String, tokenUrl: String = TOKEN_URL, onTokensRefreshed: (accessToken: String, refreshToken: String) -> Unit? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The current OAuth2 access token (Bearer token for API calls)

Link copied to clipboard

OAuth2 client ID from the Volvo Developer Portal

Link copied to clipboard

OAuth2 client secret from the Volvo Developer Portal

Link copied to clipboard
val onTokensRefreshed: (accessToken: String, refreshToken: String) -> Unit?

Callback invoked after a successful token refresh with the new access token and new refresh token. Must persist both tokens — the old refresh token is invalidated immediately.

Link copied to clipboard

The current refresh token for obtaining new access tokens

Link copied to clipboard

The Volvo ID token endpoint URL (override for testing)