refreshIfExpired

abstract suspend fun refreshIfExpired(): ERROR CLASS: Symbol not found for Result<com/okta/authfoundation/credential/kmp/Credential>

Ensures the credential has a non-expired access token, refreshing if necessary.

If the current access token has not expired, returns this credential immediately without any network call. If expired, performs a token refresh and returns a new Credential snapshot containing the refreshed token. The original snapshot is never mutated.

Typical usage:

val fresh = credential.refreshIfExpired().getOrThrow()
val accessToken = fresh.token.accessToken // guaranteed non-expired

Return

Result.success with a Credential snapshot containing a valid token, or Result.failure with:

  • IllegalStateException if the token is expired and no refresh token is available.

  • Other exceptions if the refresh network request fails.

See also

for a lightweight expiry check without network calls.