Authentication Overview
ChordianAI API uses AWS Cognito User Pools with JWT (JSON Web Tokens) for secure authentication and authorization.
Authentication Flow
Token Types
ChordianAI uses three types of tokens:
1. ID Token (from Cognito)
| Property | Value |
|---|---|
| Issuer | AWS Cognito User Pool |
| Verification | JWKS (JSON Web Key Set) |
| Purpose | Initial authentication |
| Lifespan | Short-lived (typically 1 hour) |
2. Session JWT (Server-side)
| Property | Value |
|---|---|
| Algorithm | HS256 |
| Expiration | 15 days |
| Storage | Client-side (localStorage or sessionStorage) |
| Library | jose |
| Purpose | API authentication |
3. Refresh Token
| Property | Value |
|---|---|
| Cookie Type | httpOnly |
| Expiration | 30 days |
| Purpose | Renew session JWT without re-login |
| Security | Protected from XSS attacks |
Quick Start
import requests
# 1. Login
response = requests.post(
"https://chordian-core.chordian.ai/api/auth/login",
json={
"username": "your-email@example.com",
"password": "your-password"
}
)
data = response.json()
session_token = data["token"]
# 2. Use token in API calls
headers = {
"Authorization": f"Bearer {session_token}",
"Content-Type": "application/json"
}
workflow_response = requests.post(
"https://chordian-core.chordian.ai/api/workflow/start",
headers=headers,
json={
"prompt": "Find SaaS companies",
"serviceId": "your-service-id"
}
)Security Best Practices
⚠️ Warning: Never expose your credentials or tokens in client-side code, version control, or logs.
1. Token Storage
| Method | Security Level | Recommended For |
|---|---|---|
httpOnly cookie (refresh token) | ✅ High | Production |
| Server-side session | ✅ High | Production |
localStorage | ⚠️ Medium | Development only |
sessionStorage | ⚠️ Medium | Development only |
| JavaScript variables | ❌ Low | Never |
2. Always Use HTTPS
All API calls must use HTTPS to prevent token interception.
3. Token Expiration
- Session JWT: 15 days
- Refresh Token: 30 days
- Implement automatic token refresh before expiration
4. Logout
Always clear tokens and cookies on logout:
// Logout example
await fetch('https://chordian-core.chordian.ai/api/auth/logout', {
method: 'POST',
credentials: 'include'
});
// Clear client-side storage
localStorage.removeItem('token');