- API Key Authentication - Simple header-based authentication for server-to-server integrations
- OAuth 2.0 - Industry-standard OAuth for user-facing applications
API Key Authentication
API key authentication is the recommended method for server-to-server integrations, scripts, and backend services.Overview
- Simple header-based authentication
- No token expiration by default
- Supports read and read_write scopes
- Rate limited based on API key tier
- One active API key per source (web, mobile, monitoring)
Creating an API Key
Generate New Key
Click Create API Key and select your desired scope:
- read - Read-only access to all resources
- read_write - Full read and write access
Using API Keys
Pass your API key in theX-Api-Key header with every request:
Python Example
JavaScript Example
API Key Scopes
API keys support hierarchical scopes:Read-only access to all endpoints. GET requests only.Allowed operations:
- List and view accounts
- List and view transactions
- List and view all other resources
- Creating, updating, or deleting resources
Full access to all endpoints. Includes all read permissions plus write access.Allowed operations:
- All read operations
- Create, update, and delete transactions
- Create, update, and delete tags
- Create valuations
- Trigger account syncs
- All other write operations
The
read_write scope includes all read permissions. You don’t need both.API Key Management
Viewing Usage
API key usage is tracked automatically:- Last used timestamp
- Request count in current hour
- Rate limit information
Revoking an API Key
To revoke an API key:- Go to Settings → API Key
- Click Revoke Key
- Confirm the revocation
API Key Sources
Sure tracks API keys by source to support different use cases:- web - For web-based integrations
- mobile - For mobile app integrations
- monitoring - For system monitoring and health checks
OAuth 2.0 Authentication
OAuth 2.0 is the recommended method for user-facing applications that need to access Sure on behalf of users.Overview
- Industry-standard OAuth 2.0 protocol
- Access tokens expire after 1 year
- Refresh tokens for obtaining new access tokens
- Supports PKCE for enhanced security
- Hierarchical scopes (read, read_write)
OAuth Scopes
Sure implements two OAuth scopes:Default scope providing read-only access to all resources.
Optional scope providing full read and write access. Includes all read permissions.
Token Endpoints
Sure provides dedicated endpoints for token management:Signup
Create a new user account and obtain access tokens:Invite codes may be required depending on your instance configuration.
- Minimum 8 characters
- Must include uppercase and lowercase letters
- Must include at least one number
- Must include at least one special character:
!@#$%^&*(),.?":{}|<>
Login
Authenticate an existing user:Required only if two-factor authentication is enabled for the user.
Refresh Token
Obtain a new access token using a refresh token:SSO Exchange (Mobile)
Exchange a web SSO authorization code for mobile tokens:Enable AI Features
Bearer token from login or signup
403 Forbidden: AI is not available for this account422 Unprocessable Entity: Failed to update user settings
Using OAuth Tokens
Pass your access token in theAuthorization header:
Python Example
JavaScript Example
Token Lifecycle
Obtain Initial Tokens
Use the login or signup endpoint to get your initial access and refresh tokens.
Use Access Token
Include the access token in the Authorization header for all API requests.Access tokens expire after 1 year.
Refresh Before Expiry
Before your access token expires, use the refresh endpoint to obtain new tokens.The old access token is automatically revoked.
OAuth Security Features
PKCE (Proof Key for Code Exchange)
PKCE (Proof Key for Code Exchange)
PKCE is enforced for all OAuth flows to prevent authorization code interception attacks.This is configured in
config/initializers/doorkeeper.rb:191.Token Hashing
Token Hashing
Access tokens and refresh tokens are hashed before storage using SHA256.In test environments, plaintext fallback is enabled for easier testing.
Application Secret Hashing
Application Secret Hashing
OAuth application secrets are hashed using SHA256 before storage.
Refresh Token Rotation
Refresh Token Rotation
When you refresh an access token, both the access token and refresh token are rotated. The old tokens are revoked.
Authentication Errors
Both authentication methods return consistent error responses:Unauthorized (401)
Authentication failed or credentials are missing:- API key is revoked or expired
- Access token is expired
- Authorization header is missing or malformed
- Account has been deactivated
Insufficient Scope (403)
Authentication succeeded but lacks required permissions:- Using a
readscope for write operations - API key doesn’t have the required scope
- Access token was issued with limited scopes
Choosing an Authentication Method
Use API Keys When
- Building server-to-server integrations
- Creating backend automation scripts
- Implementing system monitoring
- You don’t need per-user authentication
Use OAuth When
- Building user-facing applications
- Need to act on behalf of specific users
- Building mobile applications
- Require more granular access control
Security Best Practices
Store Credentials Securely
Use environment variables or secure credential stores (like AWS Secrets Manager or HashiCorp Vault) to store API keys and tokens.
Use HTTPS Only
Always use HTTPS when making API requests. Never send credentials over unencrypted connections.
Rotate Keys Regularly
For API keys used in production, rotate them periodically (every 90 days recommended).
Use Minimal Scopes
Only request the scopes you actually need. Use
read scope for read-only integrations.Troubleshooting
API key not working after creation
API key not working after creation
- Ensure you’re passing the key in the
X-Api-Keyheader (notAuthorization) - Verify the key hasn’t been revoked
- Check that you copied the entire key without spaces or line breaks
- Confirm your account is active
OAuth tokens expiring too quickly
OAuth tokens expiring too quickly
Access tokens expire after 1 year. If tokens seem to expire sooner:
- Check your device’s clock is synchronized
- Verify you’re not accidentally revoking tokens
- Implement proper refresh token logic
Getting 'insufficient_scope' errors
Getting 'insufficient_scope' errors
You need a higher permission level:
- For API keys: Create a new key with
read_writescope - For OAuth: Request the
read_writescope during authorization - Note: You cannot upgrade an existing token’s scope, you must obtain a new one
Cannot access resources from another family
Cannot access resources from another family
The API enforces family-level access control:
- Users can only access resources within their own family
- This is a security feature that cannot be bypassed
- Each user belongs to exactly one family
User Management
Sure’s API provides endpoints for managing user accounts. These endpoints requirewrite scope.
Reset Account
Delete Account
422 Unprocessable Entity: Failed to delete account
Next Steps
Now that you understand authentication, explore the API:API Overview
Learn about rate limits, pagination, and error handling
Accounts API
Access your accounts and balances
Transactions API
Start working with transactions
All Resources
Browse all API endpoints