Complete guide to setting up GitHub authentication for the GitHub Utilities toolkit.
GitHub Utilities uses GitHub Personal Access Tokens (PAT) for authentication. This guide covers:
- Creating and configuring tokens
- Setting up environment variables
- Security best practices
- Troubleshooting authentication issues
-
Navigate to GitHub Settings
- Go to GitHub.com
- Click your profile picture β Settings
- Scroll down to Developer settings
- Click Personal access tokens β Tokens (classic)
-
Generate New Token
- Click "Generate new token (classic)"
- Give it a descriptive name:
GitHub Utilities - [Your Machine] - Set expiration (recommended: 90 days for security)
-
Select Required Scopes
β repo # Full control of private repositories β read:org # Read organization membership β workflow # Update GitHub Action workflows (future use) β read:user # Read user profile data β user:email # Access user email addresses -
Generate and Copy Token
- Click "Generate token"
β οΈ IMPORTANT: Copy the token immediately - you won't see it again!
# Install GitHub CLI first: https://cli.github.com/
gh auth login --scopes repo,read:org,workflow,read:user,user:email# In your project root
cp issue-creator/env.example .env
# Edit .env file
echo "GITHUB_TOKEN=your_token_here" > .env# Linux/macOS
export GITHUB_TOKEN="your_token_here"
echo 'export GITHUB_TOKEN="your_token_here"' >> ~/.bashrc
# Windows PowerShell
$env:GITHUB_TOKEN="your_token_here"
[Environment]::SetEnvironmentVariable("GITHUB_TOKEN", "your_token_here", "User")# Pass token directly (less secure)
python github-issue-creator.py --token your_token_here --config config.json- Use descriptive token names with machine/purpose info
- Set reasonable expiration dates (30-90 days)
- Use minimum required scopes for your use case
- Store tokens in .env files (not in code)
- Add .env to .gitignore to prevent accidental commits
- Rotate tokens regularly
- Use different tokens for different projects/machines
- Never commit tokens to git repositories
- Don't share tokens in chat, email, or documentation
- Avoid tokens with unnecessary scopes
- Don't use tokens in CI/CD logs
- Don't store tokens in plain text files in shared locations
# Test environment loading
cd github-utilities
python -c "
import os
from dotenv import load_dotenv
load_dotenv()
token = os.getenv('GITHUB_TOKEN')
print('β
Token found' if token else 'β Token not found')
print(f'Token length: {len(token) if token else 0}')
"# Test with issue analyzer
cd issue-analyzer/
python github-issues-analyzer.py --owner microsoft --repo vscode --days 1
# Test with issue creator (dry run)
cd ../issue-creator/
python github-issue-creator.py --config config-examples/basic-config.json --dry-run| Scope | Purpose | Required For |
|---|---|---|
repo |
Full repository access | Creating/reading issues, accessing private repos |
read:org |
Read organization data | Organization-owned repositories |
workflow |
GitHub Actions access | Future automation features |
read:user |
Read user profile | User information in reports |
user:email |
Access email addresses | Assignee/author email lookup |
# Check if token is loaded
python -c "import os; print('GITHUB_TOKEN' in os.environ)"
# Test token validity
curl -H "Authorization: token YOUR_TOKEN" https://api.github.com/user"Bad credentials"
- Token is invalid or expired
- Token not properly set in environment
- Solution: Generate new token, check .env file
"Not Found" for public repositories
- Token lacks required scopes
- Repository name/owner incorrect
- Solution: Add
reposcope, verify repository details
"API rate limit exceeded"
- Too many requests in short time
- Solution: Wait for rate limit reset, use authenticated requests
"Resource not accessible by personal access token"
- Token lacks required scope for operation
- Solution: Add necessary scopes to token
- Scheduled rotation: Every 90 days
- Security incident: Immediately if token may be compromised
- Scope changes: When you need different permissions
- Team changes: When team members leave
- Generate new token with same scopes
- Test new token in development environment
- Update .env file with new token
- Revoke old token in GitHub settings
- Update any external services using the token
For organization-wide automation:
- Use GitHub Apps instead of personal tokens
- Request organization owner to create organizational tokens
- Use service accounts with dedicated tokens
# Set custom API endpoint
export GITHUB_API_URL="https://github.yourdomain.com/api/v3"- Enable SSO for your token in organization settings
- Token must be authorized for SSO before use
- GitHub Token Documentation
- GitHub API Authentication
- GitHub CLI Authentication
- Security Best Practices
π Keep your tokens secure and rotate them regularly!