API Reference
BastionAuth provides a RESTful API for all authentication operations.
Base URL
https://api.bastionauth.dev/api/v1For self-hosted deployments, replace with your API URL.
Authentication
Most endpoints require authentication via Bearer token:
curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
https://api.bastionauth.dev/api/v1/users/meEndpoints
Authentication
Sign Up
POST /auth/sign-upCreate a new user account.
Request Body:
{
"email": "user@example.com",
"password": "SecurePassword123!",
"firstName": "John",
"lastName": "Doe"
}Response:
{
"user": {
"id": "uuid",
"email": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"emailVerified": false
},
"accessToken": "eyJ...",
"refreshToken": "eyJ..."
}Sign In
POST /auth/sign-inAuthenticate an existing user.
Request Body:
{
"email": "user@example.com",
"password": "SecurePassword123!"
}Response:
{
"user": { ... },
"accessToken": "eyJ...",
"refreshToken": "eyJ..."
}Sign Out
POST /auth/sign-outInvalidate the current session.
Headers: Authorization: Bearer ACCESS_TOKEN
Refresh Token
POST /auth/refreshGet a new access token using a refresh token.
Request Body:
{
"refreshToken": "eyJ..."
}Users
Get Current User
GET /users/meGet the authenticated user's profile.
Headers: Authorization: Bearer ACCESS_TOKEN
Response:
{
"id": "uuid",
"email": "user@example.com",
"firstName": "John",
"lastName": "Doe",
"emailVerified": true,
"mfaEnabled": false,
"createdAt": "2024-01-01T00:00:00Z"
}Update Profile
PATCH /users/meUpdate the authenticated user's profile.
Request Body:
{
"firstName": "Jane",
"lastName": "Smith"
}Change Password
POST /users/me/change-passwordChange the authenticated user's password.
Request Body:
{
"currentPassword": "OldPassword123!",
"newPassword": "NewPassword456!"
}MFA (Multi-Factor Authentication)
Enable MFA
POST /auth/mfa/enableGenerate MFA setup data (TOTP secret and QR code).
Response:
{
"secret": "JBSWY3DPEHPK3PXP",
"qrCode": "data:image/png;base64,...",
"backupCodes": ["12345678", "87654321", ...]
}Verify MFA
POST /auth/mfa/verifyVerify MFA code and complete setup.
Request Body:
{
"code": "123456"
}Organizations
List Organizations
GET /organizationsGet all organizations the user belongs to.
Create Organization
POST /organizationsCreate a new organization.
Request Body:
{
"name": "My Company",
"slug": "my-company"
}Invite Member
POST /organizations/:orgId/invitationsInvite a user to join the organization.
Request Body:
{
"email": "newmember@example.com",
"role": "member"
}Error Responses
All errors follow a consistent format:
{
"error": {
"code": "AUTH_001",
"message": "Invalid credentials",
"statusCode": 401
}
}Error Codes
| Code | Description |
|---|---|
AUTH_001 | Invalid credentials |
AUTH_002 | Email already exists |
AUTH_003 | Invalid or expired token |
AUTH_004 | Email not verified |
AUTH_005 | MFA required |
AUTH_006 | Invalid MFA code |
RATE_001 | Rate limit exceeded |
VAL_001 | Validation error |
Rate Limits
| Endpoint | Limit |
|---|---|
/auth/sign-in | 5/min |
/auth/sign-up | 10/min |
/auth/mfa/* | 10/min |
| Other endpoints | 100/min |
Rate limit headers are included in responses:
X-RateLimit-Limit: Maximum requestsX-RateLimit-Remaining: Remaining requestsX-RateLimit-Reset: Reset timestamp
Webhooks
BastionAuth can send webhooks for important events:
user.createduser.updateduser.deletedsession.createdsession.revokedorganization.createdorganization.member.addedorganization.member.removed
Configure webhooks in the Admin Dashboard under Settings → Webhooks.