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

Add Envs for Github Enterprise Oauth App #404

Merged
merged 1 commit into from
Nov 5, 2024

Conversation

emplam27
Copy link
Contributor

@emplam27 emplam27 commented Nov 5, 2024

What this PR does / why we need it:

Added an envs for using passport-github on Github Enterprise Oauth app.

ref: https://github.com/jaredhanson/passport-github?tab=readme-ov-file#enterprise-corporate-github
ref: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps

Default value is for Github Oauth app. if yor want to Github Enterprise OAuth app, change those envs.

  • GITHUB_AUTHORIZATION_URL: https://github.com/login/oauth/authorize => https://ENTERPRISE_INSTANCE_URL/login/oauth/authorize
  • GITHUB_TOKEN_URL: https://github.com/login/oauth/access_token => https://ENTERPRISE_INSTANCE_URL/login/oauth/access_token
  • GITHUB_USER_PROFILE_URL: https://api.github.com/user => https://ENTERPRISE_INSTANCE_URL/api/v3/user

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Enhanced GitHub authentication with new OAuth configuration variables.
    • Improved GithubStrategy to utilize additional parameters for better integration with GitHub services.
  • Bug Fixes

    • No specific bug fixes noted in this release.
  • Documentation

    • Updated environment variable descriptions for clarity on usage in the OAuth flow.

@emplam27 emplam27 requested a review from devleejb November 5, 2024 08:13
@emplam27 emplam27 self-assigned this Nov 5, 2024
@CLAassistant
Copy link

CLAassistant commented Nov 5, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Nov 5, 2024

Walkthrough

The changes introduce new environment variables for GitHub OAuth in the backend/.env.development file, including GITHUB_AUTHORIZATION_URL, GITHUB_TOKEN_URL, and GITHUB_USER_PROFILE_URL. Additionally, the GithubStrategy class in backend/src/auth/github.strategy.ts has been updated to utilize these new variables in its configuration for the authentication strategy while keeping existing properties unchanged.

Changes

File Change Summary
backend/.env.development Added variables: GITHUB_AUTHORIZATION_URL, GITHUB_TOKEN_URL, GITHUB_USER_PROFILE_URL with descriptions and expected value formats. Existing variables remain unchanged.
backend/src/auth/github.strategy.ts Modified GithubStrategy class to include authorizationURL, tokenURL, and userProfileURL properties from ConfigService. Existing properties remain unchanged.

Poem

In the garden where code does bloom,
New paths for GitHub, we make room.
With tokens and URLs, we set the stage,
For seamless logins, we turn the page.
Hops of joy in every line,
A rabbit's cheer for code divine! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
backend/.env.development (3)

16-19: Enhance documentation for enterprise setup.

While the comment explains the basic purpose, consider adding:

  1. A note about URL validation requirements
  2. A complete example for enterprise setup
 # GITHUB_AUTHORIZATION_URL: Authorization URL for Github OAuth app. 
 # Default OAuth app is Github. Change this url for using Github Enterprise OAuth App.
 # Format: https://ENTERPRISE_INSTANCE_URL/login/oauth/authorize
+# Example for enterprise: https://github.mycompany.com/login/oauth/authorize
+# Note: URL must use HTTPS protocol
 GITHUB_AUTHORIZATION_URL=https://github.com/login/oauth/authorize

20-23: Fix inconsistent format documentation.

The format example is missing the 'Format:' prefix, unlike other environment variables in this file.

 # GITHUB_TOKEN_URL: Token URL for Github OAuth app. 
 # Default OAuth app is Github. Change this url for using Github Enterprise OAuth App.
-# https://ENTERPRISE_INSTANCE_URL/login/oauth/access_token
+# Format: https://ENTERPRISE_INSTANCE_URL/login/oauth/access_token
+# Example for enterprise: https://github.mycompany.com/login/oauth/access_token
 GITHUB_TOKEN_URL=https://github.com/login/oauth/access_token

24-27: Add API version context and fix format documentation.

The configuration should clarify the API version requirement and maintain consistent documentation format.

 # GITHUB_USER_PROFILE_URL: User profile URL for Github OAuth app. 
 # Default OAuth app is Github. Change this url for using Github Enterprise OAuth App.
-# https://ENTERPRISE_INSTANCE_URL/api/v3/user
+# Format: https://ENTERPRISE_INSTANCE_URL/api/v3/user
+# Example for enterprise: https://github.mycompany.com/api/v3/user
+# Note: The /api/v3 prefix is required for both GitHub and GitHub Enterprise
 GITHUB_USER_PROFILE_URL=https://api.github.com/user
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 516394e and 642cc03.

📒 Files selected for processing (2)
  • backend/.env.development (1 hunks)
  • backend/src/auth/github.strategy.ts (1 hunks)
🔇 Additional comments (1)
backend/src/auth/github.strategy.ts (1)

14-16: Verify the configuration loading.

The current implementation assumes the configuration values will be available. Let's verify the environment variable setup across different environments.

✅ Verification successful

Based on the verification results, I can now provide a final response:

Environment configuration is properly set up and validated

The codebase shows proper environment configuration handling:

  • Global configuration setup in app.module.ts with environment-specific file loading
  • Environment variables are properly validated using class-validator decorators
  • Configuration is properly injected via ConfigService in the GitHub strategy
  • Environment documentation exists in multiple .env.example files
  • Test coverage exists for configuration-related code
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for environment variable definitions across configuration files

# Look for GitHub OAuth URL configurations in environment files
echo "Checking environment files for GitHub OAuth URL configurations..."
rg -l "GITHUB_(AUTHORIZATION|TOKEN|USER_PROFILE)_URL" --type-add 'env:*.env*' --type env

# Check for any hardcoded GitHub URLs that might need updating
echo -e "\nChecking for potential hardcoded GitHub URLs..."
rg -i "https://(api\.)?github\.com" --type typescript

Length of output: 433


Script:

#!/bin/bash
# Let's try a different approach to find configuration files and GitHub-related URLs

# Search for env files with any extension
echo "Looking for environment files..."
fd -e env -e env.example -e env.sample -e env.template

# Search for GitHub-related environment variables in all files
echo -e "\nSearching for GitHub-related environment variables..."
rg "GITHUB_(AUTHORIZATION|TOKEN|USER_PROFILE)_URL"

# Search for GitHub URLs in all files (without type restriction)
echo -e "\nChecking for GitHub URLs in the codebase..."
rg -i "https://(api\.)?github\.com"

# Look for configuration setup in TypeScript files
echo -e "\nChecking for configuration setup in TypeScript files..."
fd -e ts -e tsx --exec grep -l "ConfigService\|ConfigModule"

Length of output: 26314


Script:

#!/bin/bash
# Let's check for environment variable configuration and validation

# Check for environment validation or configuration setup in the codebase
echo "Checking for environment validation..."
rg -A 10 "ConfigModule\.forRoot|validateSync|IsNotEmpty|IsString" backend/src/

# Check for environment variable documentation
echo -e "\nChecking for environment documentation..."
fd -e md -e env.example -e env.template --exec cat {}

# Check for environment-related tests
echo -e "\nChecking for environment-related tests..."
fd -e spec.ts -e test.ts --exec grep -l "ConfigService\|ConfigModule\|process.env"

Length of output: 51655

backend/src/auth/github.strategy.ts Show resolved Hide resolved
backend/.env.development Show resolved Hide resolved
@devleejb
Copy link
Member

devleejb commented Nov 5, 2024

Thanks for the PR. Could you sign the CLA?

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

@emplam27
Copy link
Contributor Author

emplam27 commented Nov 5, 2024

@devleejb done! thank you :)

@devleejb devleejb merged commit 72b0b1e into main Nov 5, 2024
2 checks passed
@devleejb devleejb deleted the emplam27-github-enterprise branch November 5, 2024 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants