Skip to content

Conversation

@danielcweeks
Copy link
Contributor

We've had a number of issues reported that relate to the default refresh path for tokens created through the client credentials flow. The first is that we assume that token exchange is the default refresh path and the second is that some IDPs have different behaviors around token exchange. Some disallow refreshing and fail while others support exchange without refreshing the token expiration and others fully support this approach which provides a viable refresh path. There's a lot of flexibility within spec for the RFCs governing this.

Given that many IDPs do not support this exchange and the expected path to get a new token when you have client credentials is to just use the client credentials flow, we need a way to allow that behavior.

In the future, we want to better support refresh tokens and possibly remove the exchange behavior, but regardless the recommended path for new token creation with client credentials is to use the client credential flow like proposed in this PR.

@danielcweeks danielcweeks requested a review from nastra August 13, 2025 23:02
@github-actions github-actions bot added the core label Aug 13, 2025

return response;
} else {
return fetchToken(
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to check whether we have a credential here? I think it's possible that we started just with a token and so we'd end up with null credential. We might also want to add a test for this in TestRESTCatalog, since we already have some other tests where e.g. we either start with a credential or with a token only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a check, but that's really a configuration issue since if you only have a token, then your only option is exchange flow. Disabling exchange and not having a client credential would also mean that you need to disable refresh (you won't be able to get a new token regardless).

@nastra nastra changed the title Allow disabling token exchange as refresh Core: Allow disabling token exchange as refresh Aug 14, 2025
@ValueSource(strings = {"v1/oauth/tokens", "https://auth-server.com/token"})
public void testCatalogExpiredTokenCredentialRefreshWithExchangeDisabled(String oauth2ServerUri) {
// expires at epoch second = 1
String token = ".eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjF9.";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nastra gitleaks doesn't like the JWTs that we have in the tests (we probably shouldn't have JWTs that look valid even if expired). Omitting the header and signature appears to render it harmless.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I noticed that too and and things still work as expected, the removing the header + signature should be fine, since we really only care about the expiration. Do you want to update the other tokens in this test class as well?

Copy link
Contributor

@nastra nastra left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @danielcweeks

@danielcweeks danielcweeks merged commit af82d34 into apache:main Aug 15, 2025
42 checks passed
@adutra
Copy link
Contributor

adutra commented Aug 22, 2025

Hi, would it be possible to include this in 1.10?

@nastra
Copy link
Contributor

nastra commented Aug 22, 2025

@adutra since it's already on main it will automatically be included in 1.10

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants