Conversation
When Canvas rejects a refresh token with invalid_grant, delete the stored token and restart the OAuth flow instead of rendering a 403 on every launch. The OAuth callback now uses update_or_create so re-authorizing can't collide with an existing row. Also registers CanvasOAuth2Token in the Django admin for viewing and deleting tokens. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NxgCeX8Y1zSgrACqveBrBm
It was already in .gitignore but had been committed before that rule. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NxgCeX8Y1zSgrACqveBrBm
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.
Problem
Some users (tokens issued 2026-09-08) get
refresh_token request failed to get a token: {"error":"invalid_grant","error_description":"refresh_token not found"}at/oauth/initiate. Canvas no longer recognizes their refresh token, and because the dead row is never removed, every launch fails the same way.Not caused by discarding rotated refresh tokens — Canvas doesn't rotate them ("the same refresh token can be used multiple times"), and the affected tokens were never successfully refreshed even once.
Changes
canvas.py: raiseInvalidGrantError(subclass ofInvalidOAuthReturnError) when Canvas responds 400/401 withinvalid_grant.oauth.py: onInvalidGrantErrorduring refresh, delete the token and raiseMissingTokenErrorso the middleware restarts the OAuth flow. Other failures (e.g. Canvas 5xx) still render the error page and keep the token.oauth.py: callback usesupdate_or_createso re-authorizing can't violate the one-to-one onuser.admin.py: registerCanvasOAuth2Token(list/search/delete; token values hidden; no add).Testing
Not yet exercised against Canvas. To verify: delete an affected user's token via admin (or let the new path do it) and relaunch — they should land on the Canvas authorize screen.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NxgCeX8Y1zSgrACqveBrBm