Supported Providers
GitHub
Access GitHub repositories using OAuth 2.0
GitLab
Access GitLab repositories with refresh token support
GitHub OAuth
Configuration
GitHub OAuth is configured inappsettings.json under the GitAuth.GitHub section:
Your GitHub OAuth application client ID. Create one at GitHub Developer Settings.
Your GitHub OAuth application client secret.
The local callback URL where GitHub redirects after authorization. Must match the OAuth app configuration.
OAuth scopes requested from GitHub. Default includes:
repo: Full repository access (read/write)user: Read user profile information
Example Configuration
appsettings.json
Authentication Flow
- Check Existing Credentials: Validates stored tokens before initiating OAuth
- OAuth Authorization: Opens browser to GitHub’s authorization page
- Local Callback: Listens on port 8888 for the OAuth callback
- Token Exchange: Exchanges authorization code for access token
- User Info: Retrieves user profile information
- Credential Storage: Securely stores the access token
GitHub OAuth tokens do not expire and do not support refresh tokens in this flow.
Creating a GitHub OAuth App
Navigate to GitHub Settings
Go to GitHub Developer Settings and click “New OAuth App”
Configure Application
- Application name: Chapi Assistant
- Homepage URL: Your application URL
- Authorization callback URL:
http://localhost:8888/callback
GitLab OAuth
Configuration
GitLab OAuth is configured inappsettings.json under the GitAuth.GitLab section:
Your GitLab OAuth application client ID. Create one in GitLab User Settings > Applications.
Your GitLab OAuth application client secret.
The local callback URL where GitLab redirects after authorization. Must match the OAuth app configuration.
OAuth scopes requested from GitLab. Default includes:
api: Full API accessread_user: Read user profileread_repository: Read repository datawrite_repository: Write to repositories
The base URL for your GitLab instance. Can be customized for self-hosted GitLab.
Example Configuration
appsettings.json
Authentication Flow
- Check Existing Credentials: Validates stored tokens before initiating OAuth
- OAuth Authorization: Opens browser to GitLab’s authorization page
- Local Callback: Listens on port 8891 for the OAuth callback
- Token Exchange: Exchanges authorization code for access and refresh tokens
- User Info: Retrieves user profile information
- Credential Storage: Securely stores both access and refresh tokens
GitLab OAuth tokens expire after a certain period. The refresh token is automatically used to obtain new access tokens.
Token Refresh
GitLab supports automatic token refresh using the stored refresh token:GitLabOAuthProvider.cs
Creating a GitLab OAuth App
Configure Application
- Name: Chapi Assistant
- Redirect URI:
http://localhost:8891/callback - Scopes: Select
api,read_user,read_repository,write_repository
Credential Storage
Credentials are securely stored using theICredentialStorageService interface:
- GitHub: Stores username and access token
- GitLab: Stores username, access token, and refresh token
Troubleshooting
Authentication Cancelled
Authentication Cancelled
This occurs when:
- User closes the browser before completing OAuth
- State parameter mismatch (security validation)
- Authorization code is not received
Invalid Token
Invalid Token
Token validation fails if:
- Token has been revoked in GitHub/GitLab
- Network connectivity issues
- GitLab token has expired
Port Already in Use
Port Already in Use
The callback server cannot start if the port is occupied.Solution:
- Close applications using ports 8888 (GitHub) or 8891 (GitLab)
- Change
RedirectUriin configuration to use a different port
Refresh Token Expired (GitLab)
Refresh Token Expired (GitLab)
GitLab refresh tokens can expire or become invalid.Solution: The system will automatically prompt for re-authentication.
Source Code Reference
- GitHub OAuth Provider:
~/workspace/source/Chapi/Infrastructure/Services/Auth/GitHubOAuthProvider.cs - GitLab OAuth Provider:
~/workspace/source/Chapi/Infrastructure/Services/Auth/GitLabOAuthProvider.cs - Configuration Model:
~/workspace/source/Chapi/Infrastructure/Configuration/GitAuthConfig.cs