Store the cookies from every response and send them back on every request. On Android with OkHttp, use a persistent CookieJar (for example PersistentCookieJar).The refresh call needs the refresh_token cookie, so a cookie store is the simplest option.
If the refresh also fails, send the user back to the login screen.
This also applies to the voucher and session calls: a valid api-key does not help if the request carries an expired token. Either refresh first, or don’t send the cookie on calls that only need the API key.
If several requests fail with 401 at the same time, refresh once and retry them all after it completes. The refresh token is single use, so two parallel refresh calls would make the second one fail.
Assistant
Responses are generated using AI and may contain mistakes.