fix (auth): refresh token expiry#680
Merged
alexhancock merged 1 commit intomodelcontextprotocol:mainfrom Feb 24, 2026
Merged
Conversation
Contributor
|
I also saw this behavior with the expiry. I wasn't fully sure if it was by design or a bug. My way to get around this was to implement at the credential store's load function to decrement the expire_in to reflect the actual number of seconds left for expiration (or zero once expired). |
alexhancock
approved these changes
Feb 24, 2026
Contributor
alexhancock
left a comment
There was a problem hiding this comment.
This is a good find, and thanks for preserving all the interaction with the credential store
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OAuth token expiration was not being handled correctly.
Motivation and Context
Two bugs currently exist:
expires_in()from the oauth2 crate returns the original duration from the token response (e.g., 3600s), not the time remaining. So the checkif expires_in <= Duration::from_secs(0)is always falserefresh_token()fails (e.g., refresh token revoked), the error propagates asTokenRefreshFailedinstead ofAuthorizationRequired, so it's more difficult for the client to know when to re-prompt.How Has This Been Tested?
Breaking Changes
Technically breaking, but should provide better behavior:
AuthorizationRequirederror now propagates instead ofTokenRefreshFailedto provide a clear, consistent contract for clientsTypes of changes
Checklist
Additional context
Also contains the fix from @glicht in #678 (thanks!). That should merge first for proper attribution for that fix.
AI Disclosure: AI assisted with implementation and test authoring. All changes were reviewed and guided by hand.