Quick Start: All API requests require authentication via API key in the
Authorization
header:Authentication Overview
All data in Stateset is private by default, requiring authentication for every API request. We support multiple authentication methods:Supported Authentication Methods
API Keys
Best for server-to-server communication and backend integrations
JWT Tokens
Ideal for user-specific access and session management
OAuth 2.0
Perfect for third-party integrations and partner access
Webhook Signatures
Secure webhook delivery with HMAC signatures
API Key Authentication
Key Types and Permissions
Key Type | Prefix | Use Case | Permissions |
---|---|---|---|
Secret Key | sk_live_ | Server-side operations | Full API access |
Restricted Key | rk_live_ | Limited scope access | Custom permissions |
Publishable Key | pk_live_ | Client-side operations | Read-only public data |
Test Key | sk_test_ | Development & testing | Sandbox environment |
Creating API Keys
- Navigate to Settings → API Keys in your dashboard
- Click Create New Key
- Select key type and permissions
- Copy and securely store your key
API keys are shown only once. Store them securely and never expose secret keys in client-side code.
Using API Keys
Restricted API Keys
Create keys with specific permissions for enhanced security:JWT Token Authentication
JWT tokens provide secure, stateless authentication for user sessions.JWT Token Structure
GraphQL API Authentication
GraphQL Endpoint Access
Stateset GraphQL API requires authentication via HTTP headers:GraphQL Request Example
OAuth 2.0 Authentication
For third-party integrations and partner access, we support OAuth 2.0:OAuth Flow
1
Authorization Request
2
Token Exchange
3
Use Access Token
Available Scopes
Scope | Description |
---|---|
orders:read | Read order data |
orders:write | Create and update orders |
customers:read | Read customer data |
customers:write | Manage customers |
inventory:read | View inventory levels |
inventory:write | Update inventory |
returns:* | Full returns access |
admin | Full API access |
Role-Based Access Control (RBAC)
User Roles and Permissions
Stateset implements fine-grained permissions using role-based access control:Role | Description | Default Permissions | API Key Prefix |
---|---|---|---|
anonymous | Unauthenticated user | Public read-only endpoints | N/A |
viewer | Read-only access | All read operations | rk_view_ |
operator | Standard user | CRUD on assigned resources | sk_live_ |
manager | Team manager | CRUD on team resources | sk_mgr_ |
admin | Full access | All operations | sk_admin_ |
super_admin | System admin | System configuration | sk_super_ |
Permission Matrix
Resource | Anonymous | Viewer | Operator | Manager | Admin |
---|---|---|---|---|---|
Orders | ❌ | Read | CRUD (own) | CRUD (team) | CRUD (all) |
Customers | ❌ | Read | Read (own) | CRUD (team) | CRUD (all) |
Inventory | Read | Read | Read | CRUD | CRUD |
Returns | ❌ | Read | CRUD (own) | CRUD (team) | CRUD (all) |
Reports | ❌ | Read | Read (own) | Read (team) | CRUD |
Settings | ❌ | ❌ | Read (own) | Update (team) | CRUD |
Custom Permissions with Session Variables
Implement fine-grained access control using session variables:JWT Claims Structure
Permission Checks
Webhook Authentication
Webhook Signature Verification
All webhooks from Stateset are signed for security:Security Best Practices
API Key Security
API Key Security
- Store keys in environment variables, never in code
- Use different keys for different environments
- Rotate keys regularly (every 90 days recommended)
- Use restricted keys with minimal permissions
- Monitor key usage for anomalies
Token Management
Token Management
- Implement short token lifetimes (15-30 minutes)
- Use refresh tokens for long-lived sessions
- Store tokens securely (httpOnly cookies)
- Implement token revocation
- Log all authentication events
Network Security
Network Security
- Always use HTTPS for API calls
- Implement IP allowlisting for production
- Use VPN or private networks when possible
- Enable CORS with specific origins
- Implement rate limiting per API key
Authentication Examples
React Hook with Authentication
Python Authentication Manager
Troubleshooting Authentication
Common Issues and Solutions
Issue | Cause | Solution |
---|---|---|
401 Unauthorized | Invalid or expired API key | Check key validity in dashboard |
403 Forbidden | Insufficient permissions | Verify key has required scopes |
429 Too Many Requests | Rate limit exceeded | Implement exponential backoff |
CORS Error | Cross-origin request blocked | Use server-side proxy or SDK |
Signature Mismatch | Invalid webhook secret | Verify webhook secret matches |
Debug Authentication
Next Steps: Create your first API request →