Overview
QFieldCloud API uses token-based authentication. Each request must include a valid authentication token in theAuthorization header.
The API supports two authentication methods:
- Token Authentication - Primary method for API access
- Session Authentication - Used by the web interface
Authentication Token
Authentication tokens are 100-character alphanumeric strings that expire after a configurable period (default: varies by instance).Token Format
Token Properties
- Length: 100 characters
- Type: Alphanumeric string
- Expiration: Configurable (instance-specific)
- Client-specific: Different token policies based on client type
- Multi-token: Users can have multiple active tokens for different clients
Obtaining an Authentication Token
Username/Password Login
Use the login endpoint to obtain a token with username or email and password:Success Response
The authentication token to use in subsequent API requests
ISO 8601 timestamp when the token expires
Email Login
You can also authenticate using email instead of username:Alternative Token Endpoint
The/api/v1/auth/token/ endpoint provides identical functionality to /api/v1/auth/login/:
Using Authentication Tokens
Include the token in theAuthorization header with the Token prefix:
Token Behavior
- Tokens are updated with
last_used_attimestamp on each request - Expired tokens return
401 Unauthorizedwith error codetoken_authentication_failed - Inactive user accounts return
401 Unauthorizedeven with valid tokens
SSO Authentication
QFieldCloud supports Single Sign-On (SSO) via OAuth2 providers configured through django-allauth.Listing Available Providers
Get a list of configured authentication providers:Example Response
Provider Response Fields
Provider type:
credentials for username/password, oauth2 for SSO providersUnique provider identifier (e.g.,
google, keycloak, github)Human-readable provider name
OAuth2 grant flow type:
0: Authorization Code3: Authorization Code with PKCE
OAuth2 scopes requested during authentication
Whether PKCE (Proof Key for Code Exchange) is enabled
OAuth2 token exchange endpoint
OAuth2 authorization endpoint
OAuth2 client ID for this provider
Client Types
QFieldCloud tracks different client types and applies appropriate token policies:| Client Type | User-Agent Pattern | Token Behavior |
|---|---|---|
qfield | qfield|* | Single token per user (new login invalidates old token) |
qfieldsync | * QGIS/[34]xxxx* | Single token per user |
sdk | sdk|* | Multiple tokens allowed |
cli | cli|* | Multiple tokens allowed |
browser | Browser User-Agent | Multiple tokens allowed |
worker | Internal workers | Multiple tokens allowed |
unknown | Other | Single token per user |
Setting Client Type
Set an appropriateUser-Agent header to ensure correct token handling:
Getting Current User
Retrieve the authenticated user’s information:Response
User’s primary key identifier
Username
Email address (read-only)
First name
Last name
Logging Out
Invalidate the current authentication token:Response
- Invalidates all active tokens for single-token clients (QField, QFieldSync, Unknown)
- Invalidates only the current token for multi-token clients (SDK, CLI, Browser)
- Sets token
expires_atto current time
Error Handling
Invalid Credentials
401 Unauthorized
Expired Token
401 Unauthorized
Invalid Token
401 Unauthorized
Too Many Login Attempts
401 Unauthorized
Inactive User
401 Unauthorized
Security Best Practices
Store tokens securely
Store tokens securely
- Never commit tokens to version control
- Use environment variables or secure credential storage
- Rotate tokens periodically
- Use different tokens for different applications
Use HTTPS only
Use HTTPS only
- Always use HTTPS endpoints in production
- Never send tokens over unencrypted connections
- Validate SSL certificates
Handle token expiration
Handle token expiration
- Check
expires_attimestamp before requests - Implement automatic token renewal
- Handle
401responses gracefully - Re-authenticate when tokens expire
Protect against token leakage
Protect against token leakage
- Don’t log tokens in plain text
- Use token prefixes in logs (e.g.,
Token abc***xyz) - Implement token revocation when compromised
- Monitor for suspicious token usage
Example: Complete Authentication Flow
Here’s a complete example of authenticating and making an API request:Next Steps
API Overview
Learn about API structure and conventions
Projects API
Start managing projects via API
Users API
Manage user accounts and profiles
OpenAPI Docs
Interactive API documentation