Overview
Gitea API supports multiple authentication methods to secure access to your resources. The recommended method is using personal access tokens with the Authorization header.Authentication Methods
Gitea supports the following authentication methods:- Authorization Header Token (Recommended)
- HTTP Basic Authentication
- OAuth2
- Query Parameters (Deprecated)
Personal Access Tokens
Creating a Token
Personal access tokens are the recommended way to authenticate with the Gitea API.- Log in to your Gitea instance
- Navigate to Settings → Applications → Access Tokens
- Click Generate New Token
- Enter a token name and select the required scopes
- Click Generate Token
- Copy the token immediately (it won’t be shown again)
Using Tokens in Requests
The recommended way to use tokens is via theAuthorization header with the token prefix:
Token Scopes
Tokens can be created with specific scopes to limit their permissions:| Scope Category | Read | Write | Description |
|---|---|---|---|
repo | read:repository | write:repository | Access to repositories |
admin:org | read:organization | write:organization | Organization management |
admin:public_key | read:public_key | write:public_key | SSH key management |
admin:repo_hook | read:repo_hook | write:repo_hook | Repository webhooks |
admin:org_hook | - | write:org_hook | Organization webhooks |
admin:user_hook | - | write:user_hook | User webhooks |
notification | read:notification | write:notification | Notifications |
user | read:user | write:user | User information |
admin:gpg_key | read:gpg_key | write:gpg_key | GPG key management |
admin:application | read:application | write:application | OAuth2 applications |
package | read:package | write:package | Package registry |
admin:misc | - | write:misc | Miscellaneous admin |
activitypub | read:activitypub | write:activitypub | ActivityPub federation |
The API automatically determines the required access level (read/write) based on the HTTP method. GET requests require read access, while POST/PUT/PATCH/DELETE require write access.
Public-Only Scopes
Tokens can be restricted to public resources only by appending:public to the scope:
read:repository:public- Only access public repositoriesread:organization:public- Only access public organizationsread:user:public- Only access public user information
HTTP Basic Authentication
Basic authentication uses your Gitea username and password (or token).Two-Factor Authentication (2FA)
If two-factor authentication is enabled on your account, include the TOTP code in theX-GITEA-OTP header:
OAuth2 Authentication
Gitea supports OAuth2 for third-party application authentication.Creating an OAuth2 Application
- Go to Settings → Applications → OAuth2 Applications
- Click Create a new OAuth2 Application
- Enter application details and redirect URI
- Note the Client ID and Client Secret
OAuth2 Flow
- Authorization Request:
- Token Exchange:
- Use Access Token:
OAuth2 tokens are JWT (JSON Web Tokens) and contain a dot (
.) in the token string.Query Parameter Authentication (Deprecated)
Historically, tokens could be passed as query parameters:DISABLE_QUERY_AUTH_TOKEN=true, these requests will fail with a warning in the server logs.
Sudo / Impersonation
Administrators can perform API requests on behalf of other users using the sudo feature.Using Sudo Header
Using Sudo Query Parameter
Actions Authentication
Gitea Actions workflows can authenticate using automatic task tokens:- Automatically generated for running workflows
- Scoped to the repository where the action is running
- Valid only while the task is in “running” status
Testing Authentication
Test your authentication by retrieving your user information:Security Best Practices
Use HTTPS
Always use HTTPS in production to prevent token interception
Scope Tokens
Grant minimal necessary scopes to access tokens
Rotate Tokens
Regularly rotate tokens and revoke unused ones
Secure Storage
Never commit tokens to version control or expose in logs
Managing Tokens via API
You can manage access tokens programmatically:List Tokens
Create Token
Delete Token
Creating and deleting tokens requires Basic Authentication or Reverse Proxy authentication. You cannot use a token to create another token.
Troubleshooting
401 Unauthorized
- Verify the token is correct and not expired
- Check that the token hasn’t been revoked
- Ensure you’re using the correct authentication method
403 Forbidden
- Verify the token has the required scopes
- Check if the account is active and not prohibited from login
- Ensure 2FA requirements are met if enforced
- For sudo requests, verify admin privileges
Deprecation Warnings
If you seeX-Gitea-Warning headers about deprecated authentication:
Next Steps
API Reference
Explore available API endpoints
Webhooks
Set up webhooks for event notifications