Skip to content

Conversation

@rongxin-liu
Copy link
Contributor

@rongxin-liu rongxin-liu commented Jan 20, 2026

This PR adds validation for GitHub tokens during authentication to ensure users are notified if their token is invalid or expired.

Authentication improvements:

  • Added a _validate_github_token function in lib50/authentication.py that makes an authenticated request to the GitHub API to verify the provided token, raising InvalidTokenError if the token is invalid or expired.
  • Updated the _authenticate_https function in lib50/authentication.py to call _validate_github_token after obtaining the token, and to handle invalid tokens by notifying the user, logging out, and exiting.

Error handling enhancements:

  • Added a new InvalidTokenError class to lib50/_errors.py for signaling invalid or expired GitHub tokens, and updated the error exports accordingly. [1] [2]
  • Updated imports in lib50/authentication.py to include InvalidTokenError.

Dependency and version updates:

  • Bumped the package version to 3.2.1 in setup.py to reflect these changes.
  • Added requests import in lib50/authentication.py for making HTTP requests to the GitHub API.

Copilot AI review requested due to automatic review settings January 20, 2026 13:49
@rongxin-liu rongxin-liu self-assigned this Jan 20, 2026
@rongxin-liu rongxin-liu added the enhancement New feature or request label Jan 20, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 InvalidTokenError exception 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.

@rongxin-liu rongxin-liu merged commit d1c2baf into main Jan 20, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants