Skip to content

Support for Authentication Schemes - Decouple user auth from GitHub API credentials #245

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

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

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 7, 2025

This PR implements a new authentication architecture that decouples user authentication from GitHub API credentials, addressing the security and flexibility concerns raised in the issue.

Problem

Previously, the application tightly coupled user authentication with GitHub API access:

  • Users needed GitHub API permissions (copilot, manage_billing, etc.) to view metrics
  • Only GitHub OAuth was supported for user authentication
  • User tokens were used directly for GitHub API calls

Solution

Implemented a flexible authentication scheme with three priority levels:

1. GitHub App Authentication (Recommended - New)

Uses GitHub App credentials for API calls while supporting multiple OAuth providers for user authentication:

# GitHub App handles API calls
NUXT_GITHUB_APP_ID=12345
NUXT_GITHUB_APP_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----..."
NUXT_GITHUB_APP_INSTALLATION_ID=67890

# Users authenticate via any OAuth provider
NUXT_OAUTH_GOOGLE_CLIENT_ID=your_google_client_id
NUXT_OAUTH_GOOGLE_CLIENT_SECRET=your_google_client_secret

# Optional access control
NUXT_AUTHORIZED_USERS=alice,bob,charlie

2. Personal Access Token (Legacy - Existing)

Continues to work as before for backward compatibility.

3. User OAuth Token (Deprecated - Existing)

Legacy GitHub OAuth mode continues to work but is now deprecated.

Key Features

🔐 Enhanced Security

  • Users no longer need GitHub API permissions
  • GitHub App uses minimal required permissions
  • Separate credentials for user auth vs API access

🌍 Multiple Identity Providers

  • Support for 20+ OAuth providers via nuxt-auth-utils
  • GitHub: /auth/github
  • Google: /auth/google
  • Microsoft: /auth/microsoft
  • And many more (Auth0, AWS Cognito, Discord, etc.)

👥 Flexible Authorization

  • Optional username-based access control
  • Comma-separated list in NUXT_AUTHORIZED_USERS
  • Case-insensitive matching
  • If not configured, all authenticated users are allowed

🔄 Backward Compatibility

  • All existing authentication methods continue to work
  • No breaking changes to current deployments
  • Gradual migration path available

Implementation Details

  • GitHub App Module: Handles JWT generation and installation token management with caching
  • Authorization Logic: Inline authorization checks in OAuth handlers for build compatibility
  • Enhanced Authentication Flow: Priority-based authentication selection
  • Comprehensive Documentation: Updated README with setup guides and migration instructions

Testing

  • ✅ All existing tests pass (85/85)
  • ✅ New authorization logic tested
  • ✅ Build compatibility verified
  • ✅ No breaking changes to existing functionality

Migration Guide

For existing deployments using NUXT_PUBLIC_USING_GITHUB_AUTH=true:

  1. Set up a GitHub App with required permissions
  2. Configure your preferred OAuth provider(s)
  3. Optionally set NUXT_AUTHORIZED_USERS for access control
  4. Remove NUXT_PUBLIC_USING_GITHUB_AUTH (defaults to false)

The new system provides better security, more flexibility, and easier user management while maintaining full backward compatibility.

Fixes #244.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.fontshare.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)
  • api.fontsource.org
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.bunny.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.google.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/copilot-metrics-viewer/copilot-metrics-viewer/node_modules/.bin/nuxt build (dns block)
  • fonts.googleapis.com
    • Triggering command: node (vitest 2) (dns block)
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node (vitest 3) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Aug 7, 2025

@karpikpl 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@Copilot Copilot AI changed the title [WIP] Support for Authentication Schemes Support for Authentication Schemes - Decouple user auth from GitHub API credentials Aug 7, 2025
Copilot finished work on behalf of karpikpl August 7, 2025 18:37
@Copilot Copilot AI requested a review from karpikpl August 7, 2025 18:37
@karpikpl karpikpl requested a review from Copilot August 10, 2025 02:28
Copy link
Contributor

@Copilot 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 PR implements a new authentication architecture that decouples user authentication from GitHub API credentials, providing enhanced security and flexibility. The changes introduce GitHub App authentication as the preferred method while maintaining backward compatibility with existing authentication schemes.

Key Changes

  • New GitHub App authentication module with JWT generation and token caching
  • Support for multiple OAuth providers (Google, Microsoft) beyond GitHub
  • Optional user authorization system with configurable access control
  • Enhanced authentication priority system with three tiers of authentication methods

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
server/modules/github-app-auth.ts Core GitHub App authentication module with JWT generation and token management
server/modules/authorization.ts User authorization logic for access control
server/modules/authentication.ts Enhanced authentication flow with priority-based scheme selection
server/routes/auth/github.get.ts Updated GitHub OAuth handler with authorization checks
server/routes/auth/google.get.ts New Google OAuth authentication handler
server/routes/auth/microsoft.get.ts New Microsoft OAuth authentication handler
nuxt.config.ts Configuration updates for new authentication schemes
package.json Added JWT library dependencies
README.md Comprehensive documentation for new authentication features
.env Environment variable templates for new authentication options
tests/github-app-auth.spec.ts Basic test placeholder for GitHub App authentication
tests/authorization.spec.ts Basic test placeholder for authorization module

@karpikpl karpikpl marked this pull request as ready for review August 10, 2025 02:29
@karpikpl
Copy link
Collaborator

@copilot can you merge main into this branch?
Look at code review comments.
Make sure the new features are well tested with unit tests

Copilot AI and others added 2 commits August 10, 2025 02:38
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Copy link
Contributor Author

Copilot AI commented Aug 10, 2025

@copilot can you merge main into this branch?
Look at code review comments.
Make sure the new features are well tested with unit tests

Completed all requested items:

  1. Merged main into this branch - Successfully merged with latest changes including Teams tab redesign and dependency updates

  2. Addressed code review comments - Fixed all 4 review feedback items:

    • Removed confusing GitHub App auth condition
    • Simplified OAuth authorization checks
    • Extracted magic numbers to named constants (3600s, 300s)
  3. Added comprehensive unit tests - Significantly expanded test coverage for authentication features:

    • GitHub App Authentication: 5 tests covering JWT generation, token caching, configuration validation, and error handling
    • Authorization Logic: 9 tests covering user access control, case-insensitive matching, and edge cases
    • Authentication Flow: 6 tests covering priority-based method selection and token expiry logic
    • OAuth Integration: 18 tests covering authorization logic for GitHub, Google, and Microsoft OAuth providers

Test Results: All 140 tests now pass (improved from 87), with comprehensive coverage of the new authentication features including edge cases, error scenarios, and multi-provider OAuth support.

Commit: e5e734e

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.fontshare.com
    • Triggering command: node (vitest) (dns block)
  • api.fontsource.org
    • Triggering command: node (vitest) (dns block)
  • fonts.bunny.net
    • Triggering command: node (vitest) (dns block)
  • fonts.google.com
    • Triggering command: node (vitest) (dns block)
  • fonts.googleapis.com
    • Triggering command: node (vitest 1) (dns block)
    • Triggering command: node (vitest 3) (dns block)
    • Triggering command: node (vitest 2) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of karpikpl August 10, 2025 03:03
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.

Support for Authentication Schemes
2 participants