API Authentication Guide
Secure access to the .git platform API using API keys, OAuth 2.0, or JWT tokens. This guide covers authentication methods, implementation examples, and security best practices.
Overview
The .git API uses multiple authentication methods to secure access to your repositories, deployments, and team resources. All requests to authenticated endpoints require a valid credential passed in the Authorization header.
| Method | Use Case | Lifetime | Scope Support |
|---|---|---|---|
api-key |
Scripts, CI/CD, backend services | Until revoked | Yes |
oauth2 |
Third-party apps, web clients | Refreshable | Yes |
jwt |
Internal microservices, edge functions | Short-lived (15m-24h) | Yes |
API Keys
API keys are the simplest way to authenticate. They are tied to your account and can be scoped to specific resources.
Generating a Key
- Navigate to Settings → API Keys in your dashboard
- Click Create New Key
- Assign scopes (e.g.,
repo:read,deploy:write) - Copy the key immediately. It will not be shown again.
Usage
Include your API key in the Authorization header:
OAuth 2.0
Use OAuth 2.0 when building applications that act on behalf of .git users. The flow follows the standard Authorization Code Grant.
Step 1: Redirect to Authorization
Step 2: Exchange Code for Token
The response includes access_token and refresh_token. Use the access token in subsequent API calls and refresh it before expiration.
JWT Bearer Tokens
JWTs are ideal for service-to-service communication or edge deployments. .git supports RS256-signed JWTs with custom claims for fine-grained access control.
Token Structure
Sign the JWT with your private key and register the corresponding public key in Settings → JWT Configuration.
Code Examples
Here are common patterns for authenticating across different languages:
Security Best Practices
- Rotate keys regularly: Schedule API key rotation every 90 days minimum.
- Apply least privilege: Only request scopes your application actually needs.
- Validate audiences: Always check the
audclaim when verifying JWTs. - Use HTTPS exclusively: All API requests are rejected over unencrypted connections.
- Monitor usage: Enable audit logging in the dashboard to detect anomalous access patterns.
Authentication Error Codes
| Status | Code | Description | Resolution |
|---|---|---|---|
401 |
invalid_token |
Token is malformed or expired | Verify signature and expiration time |
401 |
insufficient_scope |
Token lacks required permissions | Revoke and re-authenticate with correct scopes |
403 |
account_suspended |
Account has been restricted | Contact support or check billing status |
429 |
rate_limited |
Too many authentication attempts | Implement exponential backoff |
Frequently Asked Questions
How long do access tokens last?
API keys remain valid until manually revoked. OAuth access tokens expire after 2 hours, but refresh tokens last for 30 days.
Can I scope tokens to specific repositories?
Yes. Use the repo:read:project-slug or deploy:write:project-slug format to restrict access to individual projects.
Does .git support mTLS authentication?
Yes, mutual TLS is available for Enterprise plans. Contact our sales team to configure certificate-based authentication.