Skip to content

feat(rest): support OAuth2 token exchange refresh and recovery - #1132

Open
lishuxu wants to merge 3 commits into
apache:mainfrom
lishuxu:codex/issue-1095-oauth2-refresh
Open

lishuxu wants to merge 3 commits into
apache:mainfrom
lishuxu:codex/issue-1095-oauth2-refresh

Conversation

@lishuxu

@lishuxu lishuxu commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Honor token-exchange-enabled for credential-based catalog and contextual
session refreshes. Add Basic-authenticated recovery for expired tokens and
one final recovery attempt after retries, while preserving session identity
and public API compatibility.

Add regression coverage for refresh, recovery, shutdown, and HTTP authentication.

Validation: 580 tests passed, 1 existing test skipped; pre-commit passed.

Part of #1095.

recover
? std::unordered_map<std::string, std::string>{{"Authorization",
"Basic " +
Base64::Encode(

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we form-encode the ID and secret separately, then join them with : before Base64? For example, a+b should become a%2Bb. A secret-only credential also needs the leading :.

recover = recover || (expires_at_ != std::chrono::steady_clock::time_point{} &&
expires_at_ <= config_.now());
}
if ((!config_.exchange_enabled || recover) && config_.credential.empty()) {

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With an empty ID and secret, this skips refresh even when the HTTP client already has an Authorization header. Please keep sending the request in that case. The existing factory test can cover it with "", "".

EXPECT_FALSE(session_->IsRefreshable());
}

TEST_F(OAuth2ExchangeRefreshTest, CloseSkipsQueuedExchange) {

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd drop this test and CloseWaitsForExchangeAndStopsRetries. We already test closing before a queued refresh and during a failed request. Keep the two final-recovery tests.


INSTANTIATE_TEST_SUITE_P(
RecoveryModes, RestCatalogOAuth2RecoveryTest,
::testing::Values(OAuth2RecoveryCase{"ExpiredExchange", true, true},

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep only FinalExchange here. The loopback tests already cover both expired-token cases. Move the seventh-attempt client_credentials success case next to StopsAfterHttpRetryBudget.


INSTANTIATE_TEST_SUITE_P(
ExchangeModes, RestCatalogOAuth2RefreshTest,
::testing::Values(OAuth2RefreshModeCase{"Default", "", "", "", true},

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cut this to four cases? Unset, server default, client beats default, server override beats client.

std::shared_ptr<AuthSession> session_;
};

TEST_P(OAuth2ManagerRefreshTest, CatalogRefreshUsesConfiguredGrant) {

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The REST catalog tests already check this grant choice. I'd drop this case and keep the child-session tests. They cover inheritance and recovery with the child's own credential.

auto separator = field.find('=');
if (separator != std::string::npos) {
form.emplace(UrlEncoder::Decode(field.substr(0, separator)),
UrlEncoder::Decode(field.substr(separator + 1)));

@wgtmac wgtmac Nov 22, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we turn raw + into a space before percent-decoding? The test currently accepts + where the wire value should be %2B.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants