-
Notifications
You must be signed in to change notification settings - Fork 0
guides Authentication Setup
Detailed guide for setting up and managing authentication for COPIMA CLI Crawler.
This guide covers all three authentication methods in detail:
- Personal Access Tokens (PAT) - Simple, immediate
- OAuth2 with Explicit Tokens - Stored, auto-refresh
- OAuth2 Browser Flow - Fully automated
- Quick testing and experimentation
- CI/CD pipelines
- Automation scripts
- Short-term data extraction
- Log in to https://gitlab.com
- Click your avatar → Preferences
- In left sidebar: Access Tokens
- Click Add new token
- Log in to your GitLab instance
- Click your avatar → Preferences
- In left sidebar: Access Tokens
- Click Add new token
Token Name: copima-crawler (or descriptive name)
Expiration Date: Choose appropriate expiry:
- 30 days for testing
- 90 days for regular use
- 1 year for long-term automation
Scopes: Select these scopes:
✓ api - Full API access
✓ read_api - Read-only API access
✓ read_repository - Read repository data
Optional scopes:
✓ read_registry - For container registry data
✓ read_user - For detailed user info
Click Create personal access token.
IMPORTANT: Copy token immediately - you won't see it again!
# Save to environment variable
echo 'export GITLAB_TOKEN="glpat-xxxxxxxxxxxxxxxxxxxx"' >> ~/.bashrc
source ~/.bashrc
# Or save to secure file
echo "glpat-xxxxxxxxxxxxxxxxxxxx" > ~/.gitlab-token
chmod 600 ~/.gitlab-tokenVia Environment Variable:
export GITLAB_TOKEN="glpat-xxxxxxxxxxxxxxxxxxxx"
copima-cli-crawler crawl --host https://gitlab.comVia Command Line:
copima-cli-crawler crawl \
--host https://gitlab.com \
--token glpat-xxxxxxxxxxxxxxxxxxxxVia Configuration File:
# copima.yaml
gitlab:
host: "https://gitlab.com"
token: "glpat-xxxxxxxxxxxxxxxxxxxx"copima-cli-crawler crawl --config copima.yaml# ✅ Good - Token in environment
export GITLAB_TOKEN=$(cat ~-.gitlab-token)
# ✅ Good - Token in secure config
chmod 600 copima.yaml
# ❌ Bad - Token in command history
copima-cli-crawler crawl --token glpat-xxx
# ❌ Bad - Token in version control
git add copima.yaml # Contains token- Long-running crawls
- Multiple GitLab instances
- Token refresh required
- Team environments
For Admin:
- Admin Area → Applications
- Click New application
- Fill in:
-
Name:
COPIMA CLI Crawler -
Redirect URI:
http://localhost:3000/callback - Confidential: ✓ Yes
-
Scopes:
api,read_api,read_repository
-
Name:
- Click Save application
- Copy Application ID and Secret
For Regular Users (if enabled):
- User Settings → Applications
- Click Add new application
- Same configuration as above
You need initial access and refresh tokens. Two ways:
Option A: Manual OAuth2 Flow
Use a tool like Postman or curl to complete OAuth2 flow:
# 1. Get authorization code (open in browser)
https://gitlab.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost:3000/callback&response_type=code&scope=api read_api
# 2. Exchange code for tokens
curl -X POST https://gitlab.com/oauth/token \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "code=AUTHORIZATION_CODE" \
-d "grant_type=authorization_code" \
-d "redirect_uri=http://localhost:3000/callback"
# Response contains access_token and refresh_tokenOption B: Use COPIMA Auth Command
# Create config first
cat > copima.yaml << 'EOF'
gitlab:
host: "https://gitlab.com"
oauth2:
providers:
gitlab:
clientId: "YOUR_CLIENT_ID"
clientSecret: "YOUR_CLIENT_SECRET"
redirectUri: "http://localhost:3000/callback"
authorizationUrl: "https://gitlab.com/oauth/authorize"
tokenUrl: "https://gitlab.com/oauth/token"
scopes:
- api
- read_api
EOF
# Run auth command
copima-cli-crawler auth --config copima.yamlThis opens browser, completes OAuth2 flow, and stores tokens.
Tokens are stored in database.yaml:
users:
- id: "user-uuid"
name: "Your Name"
email: "you@example.com"
createdAt: 2025-10-20T00:00:00.000Z
updatedAt: 2025-10-20T00:00:00.000Z
accounts:
- id: "account-uuid"
accountId: "my-gitlab"
providerId: "gitlab"
userId: "user-uuid"
accessToken: "oauth2-access-token"
refreshToken: "oauth2-refresh-token"
accessTokenExpiresAt: 2025-10-20T02:00:00.000Z
scope: "api read_api"
createdAt: 2025-10-20T00:00:00.000Z
updatedAt: 2025-10-20T00:00:00.000ZSecure this file:
chmod 600 database.yaml# Use account ID to select tokens
copima-cli-crawler crawl --account-id my-gitlab
# Auto-select if only one account
copima-cli-crawler crawl- Easiest setup for most users
- Desktop/workstation environments
- Interactive sessions
Create copima.yaml:
gitlab:
host: "https://gitlab.com"
oauth2:
providers:
gitlab:
clientId: "YOUR_CLIENT_ID"
clientSecret: "YOUR_CLIENT_SECRET"
redirectUri: "http://localhost:3000/callback"
authorizationUrl: "https://gitlab.com/oauth/authorize"
tokenUrl: "https://gitlab.com/oauth/token"
scopes:
- api
- read_apicopima-cli-crawler auth --config copima.yamlWhat happens:
- Local server starts on port 3000
- Browser opens to GitLab authorization page
- You authorize the application
- GitLab redirects back with code
- Code exchanged for tokens
- Tokens saved to
database.yaml - Browser shows success message
copima-cli-crawler crawlTokens are automatically loaded and refreshed.
# Add GitLab.com account
copima-cli-crawler auth --account-id gitlab-com
# Add company GitLab account
copima-cli-crawler auth --account-id company-gitlab \
--config company-gitlab.yamlcopima-cli-crawler account:listOutput:
Stored accounts:
1. gitlab-com (gitlab.com)
- User: alice@example.com
- Status: Active
- Expires: 2025-10-20 12:00:00
2. company-gitlab (gitlab.company.com)
- User: alice@company.com
- Status: Active
- Expires: 2025-10-21 08:00:00
# Use specific account
copima-cli-crawler crawl --account-id gitlab-com
# Different account
copima-cli-crawler crawl --account-id company-gitlabcopima-cli-crawler account:remove --account-id old-accountOAuth2 tokens are automatically refreshed when:
- Access token is expired
- Request returns 401 Unauthorized
- Token expiry is within threshold
[INFO] Access token expired
[INFO] Refreshing token using refresh token...
[INFO] Token refreshed successfully
[INFO] Updated database.yaml
copima-cli-crawler account:refresh --account-id my-gitlabIf refresh token expires:
# Re-authenticate
copima-cli-crawler auth --account-id my-gitlab --forceIssue: OAuth2 auth command doesn't open browser
Solution:
# Use no-browser mode
copima-cli-crawler auth --no-browser
# Copy URL from terminal
# Open in browser manually
# Copy code from callback URL
# Paste when promptedIssue: Port 3000 is occupied
Solution:
# Use different port
copima-cli-crawler auth --port 8080
# Update redirect URI in GitLab OAuth app to matchIssue: "Invalid client" when authenticating
Causes:
- Wrong client ID/secret
- Redirect URI mismatch
Solution:
- Verify client ID and secret in GitLab
- Check redirect URI matches exactly:
- GitLab:
http://localhost:3000/callback - Config:
http://localhost:3000/callback - NO trailing slash!
- GitLab:
Issue: "Failed to refresh access token"
Causes:
- Refresh token expired
- Refresh token revoked
- Network issues
Solution:
# Re-authenticate from scratch
copima-cli-crawler auth --account-id my-gitlab --forceIssue: Token seems valid but requests fail
Causes:
- Token lacks required scopes
- Token revoked in GitLab
Solution:
- Check token scopes in GitLab
- Recreate token with correct scopes
- Re-authenticate
- Tokens not in version control
-
database.yamlhaschmod 600permissions - Config files with tokens are
.gitignored - Environment variables used for CI/CD
- Tokens rotated regularly (90 days)
- Old tokens revoked after rotation
- Minimum required scopes used
- Shared systems use dedicated tokens
Last Updated: 2025-10-20