Skip to content

Validate GitHub token in authentication - #105

Merged
rongxin-liu merged 3 commits into
mainfrom
develop
Jan 20, 2026
Merged

Validate GitHub token in authentication#105
rongxin-liu merged 3 commits into
mainfrom
develop

Conversation

@rongxin-liu

@rongxin-liurongxin-liu commented Jan 20, 2026

Copy link
Copy Markdown
Contributor

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.

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

CopilotAI left a comment

Copy link
Copy Markdown

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.

FileDescription
lib50/_errors.pyAdded new InvalidTokenError exception class and exported it in __all__
lib50/authentication.pyAdded 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.

Comment threadlib50/authentication.py
Comment threadlib50/authentication.py
Comment threadlib50/authentication.py
Comment threadlib50/authentication.py
@rongxin-liu
rongxin-liu merged commit d1c2baf into mainJan 20, 2026
1 check passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementNew feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@rongxin-liu