Authentication Guide¶
GitBridge supports multiple authentication methods for accessing GitHub repositories. This guide covers how to set up and manage authentication securely.
Authentication Methods¶
1. Personal Access Token (Recommended)¶
Personal Access Tokens (PATs) are the recommended authentication method for GitBridge.
Creating a Personal Access Token¶
- Go to GitHub → Settings → Developer settings → Personal access tokens
- Click "Generate new token" (classic or fine-grained)
- Set expiration and select scopes:
- For public repos:
public_repo
- For private repos:
repo
(full control) - For organizations:
read:org
(if needed) - Generate and copy the token
Using the Token¶
Environment Variable (Recommended):
Bash | |
---|---|
Configuration File:
Command Line (Not Recommended):
Bash | |
---|---|
2. GitHub App Installation Token¶
For organization-wide access, use GitHub App installation tokens.
3. Anonymous Access¶
Public repositories can be accessed without authentication:
Bash | |
---|---|
Note: Anonymous access has lower rate limits (60 requests/hour vs 5000 for authenticated).
4. Browser Authentication¶
The browser sync method can use session-based authentication:
YAML | |
---|---|
Security Best Practices¶
1. Token Storage¶
DO: - Use environment variables - Use secret management tools - Use GitHub's built-in secrets (for Actions) - Rotate tokens regularly
DON'T: - Commit tokens to version control - Share tokens between users - Use tokens in URLs - Log tokens
2. Token Permissions¶
Use minimal required permissions:
Repository Type | Required Scope | Permissions |
---|---|---|
Public | public_repo | Read public repositories |
Private | repo | Full control of private repositories |
Organization | read:org | Read organization data |
Workflow | workflow | Update GitHub Actions |
3. Token Rotation¶
Implement regular token rotation:
Environment-Specific Setup¶
Local Development¶
Use a .env
file (add to .gitignore
):
Load in shell:
CI/CD Pipelines¶
GitHub Actions¶
YAML | |
---|---|
Jenkins¶
Groovy | |
---|---|
GitLab CI¶
YAML | |
---|---|
Docker Containers¶
Docker | |
---|---|
Build and run:
Bash | |
---|---|
Kubernetes Secrets¶
Authentication for Different Sync Methods¶
API Method¶
The API method requires a token for private repositories:
Browser Method¶
The browser method can work with or without tokens:
With Token (Automated):
YAML | |
---|---|
Without Token (Manual Login):
YAML | |
---|---|
Rate Limits¶
GitHub enforces rate limits based on authentication:
Authentication | Rate Limit | Reset |
---|---|---|
Anonymous | 60 requests/hour | Hourly |
Personal Token | 5,000 requests/hour | Hourly |
GitHub App | 5,000-15,000 requests/hour | Hourly |
Check rate limit status:
Bash | |
---|---|
Multi-Account Setup¶
Configure multiple accounts using profiles:
YAML | |
---|---|
Use profiles:
Bash | |
---|---|
OAuth App Authentication¶
For OAuth applications:
Python | |
---|---|
Troubleshooting Authentication¶
Common Issues¶
1. Invalid Token¶
Error: 401 Unauthorized
Solution:
Bash | |
---|---|
2. Insufficient Permissions¶
Error: 403 Forbidden
Solution: - Check token scopes match repository requirements - For private repos, ensure repo
scope - For org repos, may need read:org
3. Token Expired¶
Error: 401 Bad credentials
Solution: - Generate new token - Update environment variables - Consider using tokens without expiration for automation
4. Rate Limit Exceeded¶
Error: 403 API rate limit exceeded
Solution:
Bash | |
---|---|
Debug Authentication¶
Enable debug logging to troubleshoot:
Bash | |
---|---|
This shows: - Token validation attempts - API requests with headers (tokens are masked) - Rate limit information - Authentication errors
Two-Factor Authentication (2FA)¶
If 2FA is enabled on your GitHub account:
- Personal Access Tokens work normally (recommended)
- Password authentication won't work for API
- Browser method handles 2FA during manual login
Enterprise GitHub¶
For GitHub Enterprise Server:
YAML | |
---|---|
Token Security Checklist¶
- Token stored in environment variable or secret manager
- Token has minimal required permissions
- Token rotation schedule in place
- Token not in version control
- Token not in logs or error messages
- Different tokens for different environments
- Token expiration set appropriately
- Monitoring for token usage/abuse
- Backup authentication method available
- Documentation for token generation process