onUnauthorized

open suspend fun onUnauthorized(responseHeaders: Map<String, String>): Boolean

Called by XrpcClient when a request returns HTTP 401. The provider can inspect the response headers (e.g. DPoP-Nonce) and update its internal state for a retry.

Return

true if the provider handled the error and the request should be retried with fresh authHeaders, false otherwise.


open suspend fun onUnauthorized(responseHeaders: Map<String, String>, requestAuthHeaders: Map<String, String>): Boolean

Called by XrpcClient when a request returns HTTP 401, together with the auth headers that request was sent with. This is the overload XrpcClient calls.

A 401 can arrive after the provider's credentials have changed: another request may have refreshed them while this one was in flight. What the provider holds when the 401 arrives is then not what the server rejected. requestAuthHeaders is, so a provider whose refresh spends a single-use credential should compare against it before refreshing again.

The default ignores requestAuthHeaders and delegates to the one-argument overload, so an implementation that only overrides that one behaves as before. The exception is a provider that wraps another with by delegation: delegation forwards this overload straight to the wrapped provider, so a wrapper that intercepts 401s must override it too.

Return

true if the request should be retried with fresh authHeaders, false otherwise.

Parameters

responseHeaders

The headers of the 401 response.

requestAuthHeaders

What authHeaders returned for the rejected request.