onUnauthorized
A 401 reported without the headers its request carried. The token that was rejected is then unknown and taken to be the session's current one. XrpcClient calls the two-argument overload; prefer it.
Called by XrpcClient on HTTP 401. Recovers every recoverable cause in one call so the single retry that XrpcClient performs always carries fresh state. Control flow:
If the server rotated
DPoP-Nonce, store and persist it eagerly. Persisting before any refresh attempt means a refresh that throws (e.g. transient network failure) won't lose the rotated nonce.Refresh if the session's current token is a JWT whose
expis past (or within a small skew window).If the request was sent with an access token the session no longer holds, a refresh finished while it was in flight. The 401 is about the old token: return
trueso the request is re-sent with the current one, and keep the refresh token unspent.Refresh on an explicit
WWW-Authenticate: ... error="invalid_token"challenge.If only the nonce was recoverable (new nonce already persisted in step 1), return
true. Also returntruefor ause_dpop_noncechallenge whose nonce is unchanged: a concurrent request stored it first, and this one was still sent with the stale nonce.With no challenge header and an opaque token there is no evidence either way, so refresh, as before. Any other challenge (
use_dpop_noncewithout a nonce, a rejected proof, scope), or a bare 401 against a JWT that has not expired, says nothing about the token: returnfalseand keep the refresh token unspent.
Parameters
What authHeaders returned for the rejected request. When it carries no Authorization: DPoP <token>, the rejected token is taken to be the session's current one.