OAuthClient
The network half of OAuth: build authorize URLs, exchange and refresh tokens, run the device flow. No Android dependencies, so it is unit-tested on the JVM against a local server. Tokens and codes never appear in exception messages.
Types
Functions
Link copied to clipboard
Link copied to clipboard
suspend fun exchange(flow: AuthorizationCodeFlow, attempt: OAuthClient.Attempt, code: String): OAuthTokens
Link copied to clipboard
OpenRouter's PKCE flow for apps: the result is an API key owned by the user (not a token), so it is stored like any other API key. See https://openrouter.ai/docs/use-cases/oauth-pkce.
Link copied to clipboard
Polls until the user approves (RFC 8628 §3.5): waits on authorization_pending, backs off 5s on slow_down, fails on access_denied / expired_token or when the code expires.
Link copied to clipboard
suspend fun refresh(tokenUrl: String, clientId: String, clientSecret: String?, tokens: OAuthTokens, extraParams: Map<String, String> = emptyMap()): OAuthTokens
Exchanges the refresh token; keeps the old refresh token when the server doesn't rotate it.
Link copied to clipboard