-
Notifications
You must be signed in to change notification settings - Fork 47
Fix silent auth redirect with expired client credentials #4181
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
base: main
Are you sure you want to change the base?
Conversation
d02584a to
ecac935
Compare
|
Thanks for opening this PR! I'll have a look as soon as possible :) |
b3b7d29 to
091227c
Compare
packages/browser/src/Session.ts
Outdated
| // Check if the client registration has expired before attempting silent auth. | ||
| // Expiration only applies to confidential clients (those with a secret). | ||
| // clientExpiresAt === 0 means the registration never expires. | ||
| // clientExpiresAt === undefined with a secret means legacy data — treat as expired. | ||
| if (storedSessionInfo.clientAppSecret !== undefined) { | ||
| const expiresAt = storedSessionInfo.clientExpiresAt ?? -1; | ||
| if (expiresAt !== 0 && Math.floor(Date.now() / 1000) > expiresAt) { | ||
| window.localStorage.removeItem(KEY_CURRENT_SESSION); | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this check be moved up to validateCurrentSession?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep fair point, will update when I find a few mins 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update pushed 👍
b0e4770 to
ebaee2b
Compare
When client credentials expire, the silent authentication flow now correctly detects the expiration and gracefully falls back to a logged-out state instead of redirecting to the OAuth provider and showing an error page. Adds a clientExpiresAt field to ISessionInternalInfo, reads it from storage in SessionInfoManager, and updates the CHANGELOG. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
ebaee2b to
0930fdd
Compare
|
I'm sorry, I didn't realize until now your commits weren't signed. We have a branch protection rule requiring signed commit. I can sign the commit myself, but for proper attribution I'd prefer that you setup signing keys if it's okay with you. Github provides some intructions on how to do this. If it's too much of a bother, I can go ahead with my own signature, but I would prefer you get full credit for your work :) |
This PR fixes bug #4177.
Summary
When
handleIncomingRedirect({ restorePreviousSession: true })is called with stored session data containing an expiredclient_id, the library now validates client expiration before attempting silent authentication. This prevents the redirect to the OAuth provider with invalid credentials, which previously caused users to be stuck on an error page.Changes
clientExpiresAtfield toISessionInternalInfoso client expiration data flows through the existingSessionInfoManager.get()→validateCurrentSession()→silentlyAuthenticate()pathexpiresAtfrom storage in the browserSessionInfoManager.get()and return it asclientExpiresAtsilentlyAuthenticate()using the session info fields, rather than a separate methodDesign
Rather than adding a separate
isClientExpired()method and threadingstorageUtilitythrough theClientAuthenticationconstructor, the expiration timestamp is surfaced as part of the session info that already gets retrieved during silent auth. This keeps the change minimal and avoids extra constructor parameters, mock plumbing, and redundant storage reads.Checklist
🤖 Generated with Claude Code