Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for private GitHub repository cloning with OAuth authentication #193

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JulsdL
Copy link

@JulsdL JulsdL commented Feb 19, 2025

GitHub OAuth Integration for Private Repositories

This update introduces comprehensive support for handling private GitHub repositories by integrating GitHub OAuth authentication. The key updates include:

🔑 Authentication & Repository Access

1. Secure Repository Cloning

  • Enhanced clone_repo function: Now accepts an optional OAuth token.
  • OAuth token integration: Injects the token into the GitHub repository URL for authentication.
  • Improved error handling:
    • _check_repo_exists now verifies the repository using authentication headers.
    • Ensures private repositories are only accessible with a valid token.

2. OAuth Authentication Routes

  • Introduced a new module: src/server/oauth.py.
  • Implements GitHub authentication flow using Authlib:
    • Login via GitHub.
    • Callback handling for OAuth.
    • Logout to clear sessions.

3. Session Middleware for Token Management

  • Session-based authentication integrated in src/server/main.py.
  • Stores OAuth tokens securely in cookie-based sessions.
  • Allows other endpoints (e.g., query_processor) to access and pass tokens to clone_repo.

🖥️ UI & User Experience

4. Authentication UI Updates

  • Modified navbar.jinja:
    • Displays "Login with GitHub" when no token is present.
    • Shows "Logout" when authenticated.

📖 Documentation & Configuration

5. Updated README.md

  • Guides on using private repo access.
  • Instructions for setting up OAuth credentials for:
    • Production environments.
    • Local testing.

🛠️ Miscellaneous Enhancements

6. Additional Improvements

  • .gitignore updates: Ignores new directories.
  • requirements.txt updates: Adds dependencies for:
    • Authlib
    • itsdangerous

These changes enhance security, usability, and documentation, enabling seamless private repository integration via GitHub OAuth. 🚀
login_with_github_button

logout_button
private_repo_error

- Implement token-based authentication for cloning private GitHub repositories.
- Modify _check_repo_exists to use GitHub API for repo existence check with authentication.
- Update clone_repo to handle token-based URLs for private repos.
- Add .qodo/ to .gitignore.
- Introduce OAuth authentication with GitHub to handle private repositories.
- Modify clone_repo to accept a token for authenticated cloning.
- Implement OAuth routes for login and logout in src/server/oauth.py.
- Update navbar to display login/logout options based on authentication status.
- Add session middleware to manage user sessions.
- Update query_processor to pass user token for private repo access.
- Add Authlib and itsdangerous to requirements.txt for OAuth functionality.
@JulsdL
Copy link
Author

JulsdL commented Feb 19, 2025

I'm still working on adding new tests and updating the existing ones

@JulsdL JulsdL changed the title Add support for private GitHub repository cloning with OAuth authentication feat: add support for private GitHub repository cloning with OAuth authentication Feb 19, 2025
…clone options

- Update clone_repo tests to verify that the private repository token is correctly passed to _check_repo_exists.
- Refactor test_clone_repo_with_commit and test_clone_repo_without_commit to inspect git command arguments (e.g. ensuring --recurse-submodules, shallow clone flags, and checkout behavior).
- Update error message expectations for nonexistent repositories.
- Streamline assertions in tests for invalid URLs and local paths.
- Refactor tests for custom branches and commit checkouts to verify proper argument order and flag usage.
- Add new tests to validate proper behavior for private repositories: one for a valid token scenario and one for missing token handling.
…/failure, logout) and update template directory path to src/server/templates.
@moebiussurfing
Copy link

cool !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants