API Reference

Full reference for all AuthSaas REST endpoints. All requests and responses use JSON.

Base URL#

https://your-domain.com/api/v1

Authentication Endpoints#

These endpoints authenticate end users of your app. All require a valid clientId.

Register a user#

POST/auth/register
ParameterTypeRequiredDescription
clientIdstringrequiredYour app client ID
emailstring (email)requiredUser email address
passwordstringrequiredMin 8 characters
namestringoptionalDisplay name
Response · 201
{
  "success": true,
  "data": {
    "user": { "id": "usr_xxx", "email": "user@example.com", "name": null, "roles": [], "emailVerified": false },
    "tokens": { "accessToken": "eyJ...", "refreshToken": "eyJ...", "expiresIn": 900 }
  }
}

Login#

POST/auth/login
ParameterTypeRequiredDescription
clientIdstringrequiredYour app client ID
emailstring (email)requiredUser email address
passwordstringrequiredUser password
Response · 200
{
  "success": true,
  "data": { "accessToken": "eyJ...", "refreshToken": "eyJ...", "expiresIn": 900 }
}

Refresh tokens#

POST/auth/refresh

Issues a new token pair. The submitted refresh token is immediately invalidated (rotation). Reuse detection revokes all user sessions.

ParameterTypeRequiredDescription
refreshTokenstringoptionalOmit if using httpOnly cookie
Response · 200
{
  "success": true,
  "data": { "accessToken": "eyJ...", "refreshToken": "eyJ...", "expiresIn": 900 }
}

Warning

Never store refresh tokens in localStorage. The SDK stores them in sessionStorage by default, or you can configure httpOnly cookie mode for maximum security.

Logout#

POST/auth/logout

Revokes all refresh tokens for the user. Requires a valid access token in the Authorization header.

curl -X POST /api/v1/auth/logout \
  -H "Authorization: Bearer <access_token>"

Verify email#

GET/auth/verify

Verifies a user's email address using the token sent in the verification email. Called automatically when the user clicks the link in their inbox.

ParameterTypeRequiredDescription
tokenstring (query)requiredVerification token from email link
emailstring (query)requiredUser email address
Response · 200
{
  "success": true,
  "data": { "message": "Email verified successfully." }
}

Resend verification email#

POST/auth/resend-verification

Re-sends the verification email. Rate-limited to 3 requests per 15 minutes per IP.

ParameterTypeRequiredDescription
clientIdstringrequiredYour app client ID
emailstringrequiredUser email address

Note

Generating a new token invalidates the previous one.

Tenant Endpoints#

These endpoints are for developers managing their apps. Protected routes require a tenant JWT.

Register as developer#

POST/tenant/register
ParameterTypeRequiredDescription
namestringrequiredYour full name or company name
emailstring (email)requiredDeveloper email
passwordstringrequiredMin 8 characters

Developer login#

POST/tenant/login

List apps#

GET/tenant/appsRequires Bearer token

Create app#

POST/tenant/appsRequires Bearer token
ParameterTypeRequiredDescription
namestringrequiredApp name
descriptionstringoptionalShort description
allowedOriginsstring[]requiredCORS origins e.g. ["https://myapp.com"]
Response · 201
{
  "success": true,
  "data": {
    "app": { "id": "app_xxx", "clientId": "client_xxx", "name": "My App", "isActive": true },
    "clientSecret": "sas_abc123def456..."
  }
}

Danger

clientSecret is returned once only. It is hashed server-side and cannot be recovered. Rotate via POST /tenant/apps/:id/rotate if lost.

Rotate client secret#

POST/tenant/apps/:id/rotateRequires Bearer token

Invalidates the current secret and returns a new one. Existing app users are unaffected — only API calls using the old secret will fail.

User Management#

Manage users within a specific app. All endpoints require a tenant Bearer token and an appId parameter scoped to the authenticated tenant.

List users#

GET/users?appId=xxxRequires tenant Bearer token
Response · 200
{
  "success": true,
  "data": [
    {
      "id": "usr_xxx",
      "email": "user@example.com",
      "name": "Jane Doe",
      "emailVerified": true,
      "isActive": true,
      "roles": ["user"],
      "createdAt": "2024-01-15T10:30:00.000Z"
    }
  ]
}

Toggle user status#

PATCH/users/:userIdRequires tenant Bearer token

Toggles the isActive flag for the specified user. Deactivated users cannot log in and will receive an ACCOUNT_DISABLED error.

ParameterTypeRequiredDescription
appIdstringrequiredApp ID scoped to the authenticated tenant

Set user roles#

PUT/users/:userId/rolesRequires tenant Bearer token

Replaces all current roles for the user in this app with the given array.

ParameterTypeRequiredDescription
appIdstringrequiredApp ID scoped to the authenticated tenant
rolesstring[]requiredComplete desired roles array for this user

Warning

This is a full replace, not a merge. Pass the complete desired roles array. Pass an empty array [] to remove all roles.

Role Management#

Three default roles are created automatically for every new app: owner, admin, and user. You can create additional custom roles.

RolePermissions
userread:profile, write:profile
admin+ read:users, write:users, read:audit, read:sessions
owner+ delete:users, read:roles, write:roles, delete:sessions

List roles#

GET/roles?appId=xxxRequires tenant Bearer token
Response · 200
{
  "success": true,
  "data": [
    {
      "id": "role_xxx",
      "name": "editor",
      "description": "Can read and write content",
      "permissions": ["read:profile", "write:profile", "read:users"],
      "userCount": 12
    }
  ]
}

Create role#

POST/rolesRequires tenant Bearer token
ParameterTypeRequiredDescription
appIdstringrequiredApp ID scoped to the authenticated tenant
namestringrequiredRole name (min 2 characters)
descriptionstringoptionalShort description of the role
permissionsstring[]optionalInitial permissions e.g. ["read:users","write:users"]
Response · 201
{
  "success": true,
  "data": { "id": "role_xxx", "name": "editor", "permissions": [], "userCount": 0 }
}

Update role permissions#

PUT/roles/:roleId/permissionsRequires tenant Bearer token

Full replace of permissions for the role. Available permission strings:

read:profile    write:profile
read:users      write:users     delete:users
read:roles      write:roles
read:audit
read:sessions   delete:sessions
ParameterTypeRequiredDescription
appIdstringrequiredApp ID scoped to the authenticated tenant
permissionsstring[]requiredComplete desired permissions array for this role

Error codes#

All errors follow a consistent shape:

{ "success": false, "error": "Human readable message", "code": "ERROR_CODE" }
CodeStatusMeaning
INVALID_CLIENT401clientId not found or app is disabled
EMAIL_TAKEN409Email already registered in this app
INVALID_CREDENTIALS401Wrong email or password
ACCOUNT_DISABLED403User account has been deactivated
INVALID_TOKEN401Token not found or already used
TOKEN_REUSE401Refresh token reuse — all sessions revoked
TOKEN_EXPIRED401Refresh token has expired
UNAUTHORIZED401Missing or invalid Authorization header
NOT_FOUND404Resource not found
VALIDATION_ERROR400Request body failed validation
INTERNAL_ERROR500Unexpected server error
ALREADY_VERIFIED409Email already verified
EMAIL_NOT_VERIFIED403Email not yet verified
RATE_LIMITED429Too many requests, see Retry-After header
ROLE_NOT_FOUND404Role not found
ROLE_EXISTS409Role name already exists in this app
FORBIDDEN403Insufficient role for this operation