Skip to content

Make force refresh AT also update the id token #2163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tusharpandey13
Copy link
Contributor

@tusharpandey13 tusharpandey13 commented Jun 11, 2025

Make getAccessToken({refresh:true}) also update the id token

@tusharpandey13 tusharpandey13 requested a review from a team as a code owner June 11, 2025 11:40
@tusharpandey13 tusharpandey13 changed the title make getAccessToken({refresh:force}) also update the id token Make getAccessToken({refresh:force}) also update the id token Jun 11, 2025
@tusharpandey13 tusharpandey13 changed the title Make getAccessToken({refresh:force}) also update the id token Make force refresh AT also update the id token Jun 11, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 62.50000% with 21 lines in your changes missing coverage. Please review.

Project coverage is 82.18%. Comparing base (be9b2e4) to head (6c622ee).

Files with missing lines Patch % Lines
src/server/auth-client.ts 63.63% 16 Missing ⚠️
src/server/client.ts 58.33% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2163      +/-   ##
==========================================
- Coverage   82.61%   82.18%   -0.43%     
==========================================
  Files          21       21              
  Lines        2042     2094      +52     
  Branches      358      368      +10     
==========================================
+ Hits         1687     1721      +34     
- Misses        348      364      +16     
- Partials        7        9       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

if (error) {
return [error, null];
}
return [null, filterClaims(claims)];
Copy link
Contributor

Choose a reason for hiding this comment

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

Developers may have provided their own custom filtering function for the ID token claims. In this case, we would be overriding it with the DEFAULT_ALLOWED_CLAIMS which would be inconsistent.

We might want to consider offering a hook to allow for the filtering to be customized and consistent in other places we verify and store the IDT claims.

Copy link
Member

@frederikprijck frederikprijck Jun 16, 2025

Choose a reason for hiding this comment

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

I am wondering what the reason is to not have this go through the same logic (including id token claims filtering) we already have in the callback and getAccessToken?

Comment on lines +1150 to +1152
if (!authorizationServerMetadata.issuer) {
return [new DiscoveryError("Issuer not found in metadata"), null];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The issuer can never be undefined and we don't have this check elsewhere. Is there a reason you've added this explicit check here?

Comment on lines +1147 to +1149
if (!authorizationServerMetadata.jwks_uri) {
return [new DiscoveryError("JWKS URI not found in metadata"), null];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there cases where we don't publish a jwks_uri for a tenant? Is this check needed?

Comment on lines +1169 to +1172
new OAuth2Error({
code: e.code || "ID_TOKEN_VERIFICATION_FAILED",
message: e.message || "ID token verification failed."
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's be consistent with the casing and naming of our error codes. They should be added to src/errors/index.ts.

Also, we may want to consider a custom error object here similar to what we have for AT refresh.

new URL(authorizationServerMetadata.jwks_uri)
);

const ID_TOKEN_SIGNING_ALG = "RS256";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we predefining the supported IDT algo here?

Comment on lines +428 to +429
const [profileError, newProfile] =
await this.authClient.getUserFromIdToken(tokenSet.idToken!);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be that we don't get an ID token back? I believe we require the openid scope but perhaps we should consider falling back to calling /userinfo here?

Comment on lines +19 to +27
// Mock jose.jwtVerify to prevent actual JWT verification during getAccessToken flow
vi.mock("jose", async () => {
const actual = await vi.importActual("jose");
return {
...actual,
jwtVerify: vi.fn(),
createRemoteJWKSet: vi.fn()
};
});
Copy link
Contributor

Choose a reason for hiding this comment

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

It's more preferable to mint a valid JWT than to mock the dependency.

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.

4 participants