c-thiel opened a new issue, #3768:
URL: https://github.com/apache/iceberg-rust/issues/3768
### Is your feature request related to a problem or challenge?
The REST catalog cannot recover from an expired or revoked token:
- `OAuth2Session` caches the client-credentials token forever: `expires_in`
is parsed but unused, and `auth/oauth2.rs` carries `TODO: Support automatic
token refreshing`. Once the token expires, every request fails with 401 until
the catalog is rebuilt.
- `invalidate_token` / `regenerate_token` from #1465, the workaround agreed
on in #437, went away with the `AuthManager` refactor (#2838).
- A custom `AuthManager` with its own token cache never learns that the
server rejected its token, so it cannot drop it early.
The REST spec expects clients to recover: for `419 AuthenticationTimeout` it
says "The client MAY request a new access token and retry the request", and
"401 UnauthorizedResponse SHOULD be preferred over this response type on token
expiry". PyIceberg refreshes and retries on 419.
### Describe the solution you'd like
A provided method on `AuthSession`, so the change is additive:
```rust
/// Called when the catalog answers a request this session authenticated
with 401 or 419.
/// Return `true` to have the request authenticated again and sent once more.
async fn on_unauthorized(&self, request: &HttpRequest, response:
&HttpResponse) -> Result<bool> {
Ok(false)
}
```
- `HttpClient::query_catalog`, which every catalog request goes through,
calls it on 401 or 419 and retries at most once. It skips the hook for a
request with a streaming body, and when `header.authorization` is configured,
because that header replaces the session's credentials.
- `OAuth2Session` implements it for client credentials: it clears its cached
token only if that token is the one in the rejected request, and returns
`true`. Many requests failing at once then cause a single token fetch (the
concern from #437). A static token returns `false`.
- Sessions with their own cache (contextual sessions, token exchange,
external auth libraries) can invalidate the rejected token the same way.
Refreshing the token before it expires, based on `expires_in`, would be a
separate, complementary change.
### Willingness to contribute
I can contribute to this feature independently
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]