Validate GitHub token in authentication#105
Merged
rongxin-liu merged 3 commits intomainfrom Jan 20, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds GitHub token validation to the authentication flow in lib50. The change helps detect invalid or expired GitHub tokens early in the authentication process, particularly for users working in CS50 Codespaces.
Changes:
- Added a new
InvalidTokenErrorexception class to represent invalid or expired GitHub tokens - Implemented
_validate_github_token()function that validates tokens by making an authenticated request to the GitHub API - Integrated token validation into the HTTPS authentication flow for Codespaces users
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib50/_errors.py | Added new InvalidTokenError exception class and exported it in __all__ |
| lib50/authentication.py | Added requests import, _validate_github_token() function, and integrated token validation into _authenticate_https() for Codespaces environments |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…in authentication
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.
This PR adds validation for GitHub tokens during authentication to ensure users are notified if their token is invalid or expired.
Authentication improvements:
_validate_github_tokenfunction inlib50/authentication.pythat makes an authenticated request to the GitHub API to verify the provided token, raisingInvalidTokenErrorif the token is invalid or expired._authenticate_httpsfunction inlib50/authentication.pyto call_validate_github_tokenafter obtaining the token, and to handle invalid tokens by notifying the user, logging out, and exiting.Error handling enhancements:
InvalidTokenErrorclass tolib50/_errors.pyfor signaling invalid or expired GitHub tokens, and updated the error exports accordingly. [1] [2]lib50/authentication.pyto includeInvalidTokenError.Dependency and version updates:
3.2.1insetup.pyto reflect these changes.requestsimport inlib50/authentication.pyfor making HTTP requests to the GitHub API.