TokenAuthenticator

class TokenAuthenticator(storage: ERROR CLASS: Symbol not found for CredentialStorage, authService: ERROR CLASS: Symbol not found for AuthenticationService, config: ERROR CLASS: Symbol not found for ApiConfig)

OkHttp okhttp3.Authenticator that automatically refreshes the Bearer access token whenever a 401 Unauthorized response is received from a Bearer-protected endpoint.

On a 401 the authenticator:

  1. Verifies the failed request was using Bearer auth (skips Basic-Auth or unauthenticated requests).

  2. Guards against infinite retry loops (max 1 retry per request).

  3. Calls the MTN MoMo token endpoint via a dedicated AuthenticationService backed by a Basic-Auth-only OkHttpClient with no authenticator, avoiding circular dependency.

  4. Saves the refreshed Bearer token to CredentialStorage.

  5. If the OAuth2 access token is also expired, refreshes it via AuthenticationService.getOauth2AccessToken and saves it to CredentialStorage.

  6. Returns the original request without modification — the io.rekast.sdk.network.interceptor.auth.AccessTokenInterceptor will read the new token from storage and attach the correct header on the retry pass.

Parameters

storage

Encrypted credential store; used to read the API key and save refreshed tokens.

authService

Token-refresh-only AuthenticationService backed by a Basic-Auth-only client.

config

SDK configuration; supplies the target environment for OAuth2 token refresh calls.

Constructors

Link copied to clipboard
constructor(storage: ERROR CLASS: Symbol not found for CredentialStorage, authService: ERROR CLASS: Symbol not found for AuthenticationService, config: ERROR CLASS: Symbol not found for ApiConfig)

Functions

Link copied to clipboard
fun authenticate(route: ERROR CLASS: Symbol not found for Route??, response: ERROR CLASS: Symbol not found for Response): ERROR CLASS: Symbol not found for Request??

Called by OkHttp whenever a response with HTTP 401 is received.