TokenAuthenticator
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:
Verifies the failed request was using Bearer auth (skips Basic-Auth or unauthenticated requests).
Guards against infinite retry loops (max 1 retry per request).
Calls the MTN MoMo token endpoint via a dedicated AuthenticationService backed by a Basic-Auth-only OkHttpClient with no authenticator, avoiding circular dependency.
Saves the refreshed Bearer token to CredentialStorage.
If the OAuth2 access token is also expired, refreshes it via AuthenticationService.getOauth2AccessToken and saves it to CredentialStorage.
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
Encrypted credential store; used to read the API key and save refreshed tokens.
Token-refresh-only AuthenticationService backed by a Basic-Auth-only client.
SDK configuration; supplies the target environment for OAuth2 token refresh calls.
Constructors
Functions
Called by OkHttp whenever a response with HTTP 401 is received.