API Tokens for Configuration Discovery
API tokens allow OpenRegister to discover and import configurations from GitHub and GitLab repositories. This guide explains how to obtain and configure these tokens.
Overview
The Configuration Discovery feature enables you to search for and import OpenRegister configurations shared by the community. To use this feature, you need to configure API tokens for:
- GitHub - Access GitHub's Code Search API
- GitLab - Access GitLab's Global Search API
API tokens are optional. You can still manually import configurations using direct URLs without configuring tokens.
GitHub Personal Access Token
Creating a GitHub Token
-
Log in to GitHub
- Navigate to github.com and sign in
-
Access Token Settings
- Click your profile picture in the top-right corner
- Select 'Settings' from the dropdown menu
- Scroll down the left sidebar and click 'Developer settings'
- Click 'Personal access tokens' → 'Tokens (classic)'
-
Generate New Token
- Click 'Generate new token' → 'Generate new token (classic)'
- Give your token a descriptive name (e.g., 'OpenRegister Configuration Discovery')
- Set an expiration date (recommended: 90 days or custom)
-
Select Scopes
- Check the
reposcope - This grants access to the Code Search API which is required
- Check the
-
Generate and Copy
- Click 'Generate token' at the bottom
- Important: Copy the token immediately - you won't be able to see it again!
- The token will look like:
ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Token Format
GitHub Personal Access Tokens start with:
ghp_for personal access tokensgithub_pat_for fine-grained personal access tokens
Required Permissions
| Scope | Why Needed |
|---|---|
repo | Access the Code Search API to find OpenRegister configuration files |
Never share your GitHub token. Treat it like a password. If compromised, revoke it immediately and generate a new one.
GitLab Personal Access Token
Creating a GitLab Token
-
Log in to GitLab
- Navigate to gitlab.com and sign in
- For self-hosted instances, use your GitLab URL
-
Access Token Settings
- Click your profile picture in the top-right corner
- Select 'Edit profile' or 'Preferences'
- In the left sidebar, click 'Access Tokens'
-
Create New Token
- Enter a token name (e.g., 'OpenRegister Configuration Discovery')
- Set an expiration date (optional but recommended)
- Select the
read_apiscope
-
Generate Token
- Click 'Create personal access token'
- Important: Copy the token immediately - you won't be able to see it again!
- The token will look like:
glpat-xxxxxxxxxxxxxxxxxxxx
Token Format
GitLab Personal Access Tokens start with:
glpat-for personal access tokens
Required Permissions
| Scope | Why Needed |
|---|---|
read_api | Access GitLab's Global Search API to find OpenRegister configuration files |
Self-Hosted GitLab Instances
If you're using a self-hosted GitLab instance:
- Follow the same token creation process on your GitLab instance
- In OpenRegister settings, configure the 'GitLab Instance URL' field
- Enter your GitLab API base URL (e.g.,
https://gitlab.yourcompany.com/api/v4) - Leave this field empty if using GitLab.com
Configuring Tokens in OpenRegister
Step 1: Navigate to Settings
- Open your Nextcloud instance
- Go to Settings → Administration → OpenRegister
- Scroll to the API Token Configuration section
Step 2: Enter Your Tokens
GitHub Token
- Paste your GitHub Personal Access Token in the 'GitHub Token' field
- Click 'Save GitHub Token'
- You should see a success message
GitLab Token
- Paste your GitLab Personal Access Token in the 'GitLab Token' field
- (Optional) If using self-hosted GitLab, enter your GitLab API URL
- Click 'Save GitLab Token'
- You should see a success message
Step 3: Test the Configuration
- Navigate to Configurations in OpenRegister
- Click '+ Import Configuration'
- Go to the 'Discover' tab
- Try searching for configurations:
- Click 'Search GitHub' to test GitHub integration
- Click 'Search GitLab' to test GitLab integration
If configured correctly, you should see search results from the respective platforms.
Security Best Practices
Token Management
- Rotate Regularly: Change your tokens every 90 days
- Use Minimal Permissions: Only grant the required scopes
- Revoke Unused Tokens: Delete tokens you're no longer using
- Monitor Usage: Check token activity in GitHub/GitLab settings
Storage
- Tokens are stored encrypted in your Nextcloud database
- Only administrators can view and modify API tokens
- Tokens are masked in the UI (only first/last 4 characters visible)
Revoking Tokens
If a token is compromised:
- GitHub: Settings → Developer settings → Personal access tokens → Revoke
- GitLab: Preferences → Access Tokens → Revoke
- OpenRegister: Click 'Clear Token' to remove from OpenRegister
- Generate a new token and reconfigure
Troubleshooting
"401 Unauthorized" Errors
If you see unauthorized errors when discovering configurations:
-
Verify Token is Correct
- Re-enter the token in settings
- Ensure you copied the complete token
-
Check Token Permissions
- GitHub: Verify
reposcope is enabled - GitLab: Verify
read_apiscope is enabled
- GitHub: Verify
-
Token Expiration
- Check if your token has expired
- Generate a new token if necessary
-
Rate Limiting
- GitHub allows 30 code searches per minute
- Wait a few minutes and try again
No Search Results
If searches return no results:
-
Try Different Search Terms
- Leave empty to browse all OpenRegister configurations
- Use specific keywords to narrow results
-
Check Token Configuration
- Ensure token is properly saved
- Test with the opposite platform (GitHub vs GitLab)
-
Verify Platform Access
- Confirm you can access the platform directly
- Check for service outages
Self-Hosted GitLab Issues
If using self-hosted GitLab:
-
Verify URL Format
- Must include
/api/v4(e.g.,https://gitlab.company.com/api/v4) - Use HTTPS if possible
- Must include
-
Network Access
- Ensure your Nextcloud server can reach your GitLab instance
- Check firewall rules
-
Certificate Issues
- For self-signed certificates, you may need to configure certificate trust
API Rate Limits
Be aware of rate limits for API calls:
GitHub
- Authenticated: 5,000 requests per hour
- Code Search: 30 requests per minute
- Unauthenticated: 60 requests per hour (not usable for code search)
GitLab
- Authenticated: 2,000 requests per minute (GitLab.com)
- Self-Hosted: Configurable by administrator
Rate limit headers are returned with each API response. OpenRegister respects these limits automatically.
Further Reading
- GitHub Personal Access Tokens Documentation
- GitLab Personal Access Tokens Documentation
- GitHub Code Search API
- GitLab Search API
Support
If you encounter issues:
- Check this documentation for troubleshooting steps
- Contact your system administrator for support
- Contact your system administrator
- Report bugs on GitHub Issues