Skip to content

Authentication

Registration, login, OTP, password reset, refresh tokens, MFA and passkeys.

Auth Endpoints

Method Endpoint Description Authentication Required
POST /api/v1/auth/login Authenticate user and receive access + refresh tokens No
POST /api/v1/auth/register Register a new user account No
POST /api/v1/auth/otp-verification Verify OTP for account activation No
POST /api/v1/auth/forgot-password Request password reset verification code No
POST /api/v1/auth/reset-password Reset password using verification code No
POST /api/v1/auth/refresh-token Refresh access token using refresh token No
POST /api/v1/auth/logout Logout and revoke refresh token Yes
PUT /api/v1/auth/change-password Change password for authenticated user Yes
POST /api/v1/auth/mfa/setup Start TOTP MFA setup and get the secret Yes
POST /api/v1/auth/mfa/enable Enable TOTP MFA after verifying a code Yes
POST /api/v1/auth/mfa/disable Disable TOTP MFA after verifying a code Yes
POST /api/v1/auth/social/google Google social login with an ID token No
POST /api/v1/auth/passkeys/login/options Start passkey login No
POST /api/v1/auth/passkeys/login Finish passkey login No
GET /api/v1/auth/passkeys List my passkeys Yes
POST /api/v1/auth/passkeys/register/options Start passkey registration Yes
POST /api/v1/auth/passkeys/register Finish passkey registration Yes
DELETE /api/v1/auth/passkeys/{id} Delete a passkey Yes
PUT /api/v1/admin/auth/{userId}/change-user-type Change user's account type Yes (Admin + user:manage)
PUT /api/v1/admin/auth/{userId}/deactivate Deactivate user account Yes (Admin + user:manage)
PUT /api/v1/admin/auth/{userId}/activate Activate user account Yes (Admin + user:manage)
GET /api/v1/admin/users Admin: search users Yes
GET /api/v1/admin/users/{id} Admin: user detail Yes
PUT /api/v1/admin/users/{id}/activate Admin: activate a user Yes
PUT /api/v1/admin/users/{id}/deactivate Admin: deactivate a user Yes
GET /api/v1/admin/users/{id}/login-attempts Admin: inspect login/OTP lockouts Yes
PUT /api/v1/admin/users/{id}/type Admin: change a user's role Yes
POST /api/v1/admin/users/{id}/unlock Admin: clear login and OTP lockouts Yes

Authorization model

user_type is the account kind:

  • CUSTOMER
  • SELLER
  • ADMIN

Platform roles and permissions are stored in the database and resolved on every request:

  • ADMIN alone grants console entry, not permissions.
  • An admin with no role has no effective permissions.
  • SUPER_ADMIN is a legacy enum value mapped to the platform:super_admin role.
  • Effective permissions are returned by GET /api/v1/me/permissions.
  • See Users, Roles & Permissions for roles, scopes and endpoints.

Endpoint Details

1. User Login

POST /api/v1/auth/login

Request Parameters

Parameter Type Required Description
email string Yes User's email address
password string Yes User's password
userType string Yes Type of user (customer, seller, admin)
mfaCode string Conditional 6-digit TOTP code. Required when MFA is enabled for the account

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/login' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "customer@gmail.com",
    "password": "Password123!",
    "userType": "customer"
  }'

Response

Status: 200 OK

{
  "user": {
    "id": "ce563774-d3d5-442e-ad1a-b884bb0a53f0",
    "email": "customer@gmail.com",
    "userType": "customer"
  },
  "accessToken": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "expiresIn": 86400
}

Error Responses

Invalid Credentials (401):

{
  "message": "Invalid email or password. 3 attempts remaining."
}

Account Locked (400):

{
  "message": "Account locked due to too many failed login attempts. Try again in 30 minutes."
}


2. User Registration

POST /api/v1/auth/register

Key Features

  • Multiple user types supported for self-registration (customer, seller)
  • Same email can be used for different user types
  • Automatic email verification process
  • Password strength validation enforced

Request Parameters

Parameter Type Required Description
email string Yes User's email address
password string Yes User's password (min 8 chars, uppercase, lowercase, digit, special char)
userType string Yes Type of user (customer, seller)

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/register' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "piash@gmail.com",
    "password": "Str0ng!Pass",
    "userType": "customer"
  }'

Response

Status: 201 Created

{
  "id": "f48ec4f9-5482-4a23-9e49-e69f97bd20a6",
  "email": "piash@gmail.com"
}

3. OTP Verification

POST /api/v1/auth/otp-verification

Request Body

Parameter Type Required Description
userId string Yes User ID received during registration
otp string Yes OTP code sent to user's email

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/otp-verification' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "userId": "3842e19b-2608-40f8-98bd-6a6b43939fec",
    "otp": "560674d"
  }'

Response

Status: 200 OK

true

4. Forgot Password

POST /api/v1/auth/forgot-password

Request Body

Parameter Type Required Description
email string Yes User's email address
userType string Yes Specify user type (customer, seller, admin)

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/forgot-password' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "piash@gmail.com",
    "userType": "customer"
  }'

Response

Status: 200 OK

{
  "message": "Verification code sent to your email"
}

5. Reset Password

POST /api/v1/auth/reset-password

Request Body

Parameter Type Required Description
email string Yes User's email address
otp string Yes Verification code from email
newPassword string Yes New password (min 8 chars, uppercase, lowercase, digit, special char)
userType string Yes Specify user type if multiple accounts exist

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/reset-password' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "email": "piash@gmail.com",
    "otp": "9889",
    "newPassword": "Str0ng!NewPass",
    "userType": "customer"
  }'

Response

Status: 200 OK

{
  "message": "Password reset successful"
}

6. Refresh Token

POST /api/v1/auth/refresh-token
Parameter Type Required Description
refreshToken string Yes Refresh token received during login

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/refresh-token' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
    "refreshToken": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  }'

Response

Status: 200 OK

{
  "accessToken": "eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "b2c3d4e5-f6g7-8901-bcde-fg2345678901",
  "expiresIn": 86400
}

Error Responses

Invalid/Expired Token (404):

{
  "message": "Invalid or expired refresh token"
}


7. Logout

POST /api/v1/auth/logout
Header Value Required
Authorization Bearer <access_token> Yes
Content-Type application/json Yes

Request Body

Parameter Type Required Description
refreshToken string No Specific refresh token to revoke (if empty, all user tokens revoked)

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/logout' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{
    "refreshToken": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
  }'

Response

Status: 200 OK

{
  "message": "Logged out successfully"
}

8. Change Password

PUT /api/v1/auth/change-password
Parameter Type Required Description
oldPassword string Yes Current password
newPassword string Yes New password

Headers

Header Value Required
Authorization Bearer <access_token> Yes
Content-Type application/json Yes

Request

curl -X 'PUT' \
  'http://localhost:8080/api/v1/auth/change-password' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{
    "oldPassword": "Password123!",
    "newPassword": "NewPassword123!"
  }'

Response

Status: 200 OK

"Password has been changed"

9. Change User Type

PUT /api/v1/admin/auth/{userId}/change-user-type
Parameter Type Required Description
userId string Yes Unique identifier of the user to update

Query Parameters

Parameter Type Required Description
userType string Yes New account type (CUSTOMER, SELLER, ADMIN; SUPER_ADMIN is legacy)

Headers

Header Value Required
accept application/json Yes
Authorization Bearer <access_token> Yes (Admin + user:manage)

Request

curl -X 'PUT' \
  'http://localhost:8080/api/v1/admin/auth/a67fd0cc-3d92-4259-bbd4-1e0ba49dece4/change-user-type?userType=ADMIN' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...'

Response

Status: 200 OK

"User type changed successfully to ADMIN"

10. Deactivate User

PUT /api/v1/admin/auth/{userId}/deactivate
Parameter Type Required Description
userId string Yes Unique identifier of the user to deactivate

Headers

Header Value Required
accept application/json Yes
Authorization Bearer <access_token> Yes (Admin + user:manage)

Request

curl -X 'PUT' \
  'http://localhost:8080/api/v1/admin/auth/a67fd0cc-3d92-4259-bbd4-1e0ba49dece4/deactivate' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...'

Response

"User deactivated successfully"

11. Activate User

PUT /api/v1/admin/auth/{userId}/activate
Parameter Type Required Description
userId string Yes Unique identifier of the user to activate

Headers

Header Value Required
accept application/json Yes
Authorization Bearer <access_token> Yes (Admin + user:manage)

Request

curl -X 'PUT' \
  'http://localhost:8080/api/v1/admin/auth/a67fd0cc-3d92-4259-bbd4-1e0ba49dece4/activate' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...'

Response

"User activated successfully"

12. Start MFA Setup

POST /api/v1/auth/mfa/setup
Header Value Required
Authorization Bearer <access_token> Yes

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/mfa/setup' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...'

Response

Status: 200 OK

{
  "secret": "JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP",
  "otpauthUrl": "otpauth://totp/Ktor%20E-Commerce:customer@gmail.com?secret=JBSWY3DPEHPK3PXPJBSWY3DPEHPK3PXP&issuer=Ktor%20E-Commerce&digits=6&period=30"
}

13. Enable MFA

POST /api/v1/auth/mfa/enable
Parameter Type Required Description
code string Yes 6-digit TOTP code from the authenticator app

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/mfa/enable' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{ "code": "123456" }'

Response

Status: 200 OK

{ "message": "MFA enabled" }

14. Disable MFA

POST /api/v1/auth/mfa/disable
Parameter Type Required Description
code string Yes 6-digit TOTP code from the authenticator app

Request

curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/mfa/disable' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{ "code": "123456" }'

Response

Status: 200 OK

{ "message": "MFA disabled" }

15. Social login

POST /api/v1/auth/social/google
{ "idToken": "google-id-token", "mfaCode": "123456" }

mfaCode is required when the linked account has TOTP MFA enabled.

The server verifies the token through Google's tokeninfo endpoint and checks:

  • aud matches GOOGLE_CLIENT_ID
  • email_verified = true
  • exp is in the future

Existing customers are matched by email; new verified customer accounts are created automatically and the Google sub is linked as the social identity. The response is the same token payload as password login.

Passkeys (WebAuthn)

Passkeys enable passwordless login with platform authenticators.

  1. Start registration (authenticated):
curl -X POST 'http://localhost:8080/api/v1/auth/passkeys/register/options' \
  -H 'Authorization: Bearer <token>'
  1. Finish registration with the authenticator result:
{
  "credentialId": "base64url-credential-id",
  "clientDataJson": "base64url-client-data",
  "publicKey": "base64-spki-public-key",
  "name": "Laptop",
  "transports": ["internal"],
  "password": "current-password"
}

Passkey registration and deletion require step-up re-authentication. Supply the current password, or the current TOTP mfaCode when MFA is enabled. Accounts with MFA must supply a valid MFA code.

  1. Start login (public):
{ "email": "customer@example.com", "userType": "customer" }
  1. Finish login with the assertion:
{
  "email": "customer@example.com",
  "userType": "customer",
  "credentialId": "base64url-credential-id",
  "clientDataJson": "base64url-client-data",
  "authenticatorData": "base64url-authenticator-data",
  "signature": "base64url-signature",
  "mfaCode": "123456"
}

Validation:

  • challenge is single-use and expires after 5 minutes
  • ceremony type (webauthn.create / webauthn.get) and origin must match
  • ES256 signatures are verified against the stored SPKI public key
  • credentials are scoped to the owning user
  • when WEBAUTHN_REQUIRE_UV=true, the authenticator must assert user verification (UV)
  • passkey changes require recent password/MFA re-authentication

Configuration:

GOOGLE_CLIENT_ID=
WEBAUTHN_RP_ID=localhost
WEBAUTHN_RP_NAME=Ktor E-Commerce
WEBAUTHN_ORIGIN=http://localhost:3000
WEBAUTHN_REQUIRE_UV=false

Delete a passkey with a step-up body:

curl -X DELETE 'http://localhost:8080/api/v1/auth/passkeys/<id>' \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{"password":"current-password"}'

Passkey login returns the same access/refresh token pair as password login. When the account has TOTP MFA enabled, mfaCode is required. The authenticator RP-ID hash, user-presence flag and signature counter are validated; a counter regression is rejected. Attestation statement verification is intentionally left to the relying-party deployment; this API stores the registered SPKI key and verifies assertions.


Administrative Auth Endpoints

Administrative Auth Endpoints Table

Method Endpoint Description Authentication Required
PUT /api/v1/admin/auth/{userId}/change-user-type Change user's account type Yes (Admin + user:manage)
PUT /api/v1/admin/auth/{userId}/deactivate Deactivate user account Yes (Admin + user:manage)
PUT /api/v1/admin/auth/{userId}/activate Activate user account Yes (Admin + user:manage)

16. Start passkey login

POST /api/v1/auth/passkeys/login/options
curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/passkeys/login/options' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "jane@example.com",
  "userType": "CUSTOMER"
}'

Response

{
  "challenge": "string",
  "rpId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "timeout": 1,
  "allowCredentials": [
    {
      "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
      "type": "CUSTOMER",
      "transports": [
        "string"
      ]
    }
  ],
  "userVerification": "string"
}

17. Finish passkey login

POST /api/v1/auth/passkeys/login
curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/passkeys/login' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "jane@example.com",
  "userType": "CUSTOMER",
  "credentialId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "clientDataJson": "string",
  "authenticatorData": "string",
  "signature": "string",
  "mfaCode": "SAVE10"
}'

Response

{
  "user": {
    "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
    "email": "jane@example.com",
    "isVerified": true,
    "userType": "CUSTOMER",
    "isActive": true,
    "mfaEnabled": false,
    "createdAt": "2024-05-06T12:00:00",
    "updatedAt": "2024-05-06T12:00:00"
  },
  "accessToken": "token-value",
  "refreshToken": "token-value",
  "expiresIn": 1,
  "tokenType": "CUSTOMER"
}

18. List my passkeys

GET /api/v1/auth/passkeys
curl -X 'GET' \
  'http://localhost:8080/api/v1/auth/passkeys' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>'

Response

[
  {
    "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
    "credentialId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
    "name": "Example",
    "transports": "string",
    "signCount": 1,
    "createdAt": "2024-05-06T12:00:00",
    "lastUsedAt": "2024-05-06T12:00:00"
  }
]

19. Start passkey registration

POST /api/v1/auth/passkeys/register/options
curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/passkeys/register/options' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>'

Response

{
  "challenge": "string",
  "rpId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "rpName": "string",
  "userId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "userName": "string",
  "userDisplayName": "string",
  "timeout": 1,
  "excludeCredentials": [
    {
      "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
      "type": "CUSTOMER",
      "transports": [
        "string"
      ]
    }
  ],
  "userVerification": "string"
}

20. Finish passkey registration

POST /api/v1/auth/passkeys/register
curl -X 'POST' \
  'http://localhost:8080/api/v1/auth/passkeys/register' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "credentialId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "clientDataJson": "string",
  "publicKey": "string",
  "name": "Example",
  "transports": [
    "string"
  ],
  "password": "string",
  "mfaCode": "SAVE10"
}'

Response

{
  "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "credentialId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "name": "Example",
  "transports": "string",
  "signCount": 1,
  "createdAt": "2024-05-06T12:00:00",
  "lastUsedAt": "2024-05-06T12:00:00"
}

21. Delete a passkey

DELETE /api/v1/auth/passkeys/{id}
curl -X 'DELETE' \
  'http://localhost:8080/api/v1/auth/passkeys/6c5078d3-f8e3-4c88-9afe-48b5423c664f' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "password": "string",
  "mfaCode": "SAVE10"
}'

Response

{
  "message": "Operation completed"
}

22. Admin: search users

GET /api/v1/admin/users
curl -X 'GET' \
  'http://localhost:8080/api/v1/admin/users?page=1&perPage=20&userType=CUSTOMER&active=true&query=phone' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>'

Response

{
  "data": [
    {
      "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
      "email": "jane@example.com",
      "userType": "CUSTOMER",
      "isVerified": true,
      "isActive": true,
      "mfaEnabled": false,
      "isGuest": false,
      "createdAt": "2024-05-06T12:00:00"
    }
  ],
  "metadata": {
    "totalCount": 1,
    "limit": 20,
    "offset": 0,
    "page": 1,
    "perPage": 20,
    "totalPages": 1,
    "hasNext": false,
    "hasPrev": false
  }
}

23. Admin: user detail

GET /api/v1/admin/users/{id}
curl -X 'GET' \
  'http://localhost:8080/api/v1/admin/users/6c5078d3-f8e3-4c88-9afe-48b5423c664f' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>'

Response

{
  "user": {
    "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
    "email": "jane@example.com",
    "userType": "CUSTOMER",
    "isVerified": true,
    "isActive": true,
    "mfaEnabled": false,
    "isGuest": false,
    "createdAt": "2024-05-06T12:00:00"
  },
  "sellerId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "shopId": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "shopStatus": "PENDING",
  "kycStatus": "NOT_SUBMITTED",
  "orderCount": 1
}

24. Admin: activate a user

PUT /api/v1/admin/users/{id}/activate
curl -X 'PUT' \
  'http://localhost:8080/api/v1/admin/users/6c5078d3-f8e3-4c88-9afe-48b5423c664f/activate' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>'

Response

{
  "message": "Operation completed"
}

25. Admin: deactivate a user

PUT /api/v1/admin/users/{id}/deactivate
curl -X 'PUT' \
  'http://localhost:8080/api/v1/admin/users/6c5078d3-f8e3-4c88-9afe-48b5423c664f/deactivate' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>'

Response

{
  "message": "Operation completed"
}

26. Admin: inspect login/OTP lockouts

GET /api/v1/admin/users/{id}/login-attempts
curl -X 'GET' \
  'http://localhost:8080/api/v1/admin/users/6c5078d3-f8e3-4c88-9afe-48b5423c664f/login-attempts' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>'

Response

[
  {
    "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
    "email": "jane@example.com",
    "userType": "CUSTOMER",
    "ipAddress": "123 Main St",
    "attemptCount": 1,
    "lockedUntil": "2024-05-06T12:00:00",
    "isLocked": true
  }
]

27. Admin: change a user's role

PUT /api/v1/admin/users/{id}/type
curl -X 'PUT' \
  'http://localhost:8080/api/v1/admin/users/6c5078d3-f8e3-4c88-9afe-48b5423c664f/type' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "userType": "CUSTOMER"
}'

Response

{
  "message": "Operation completed"
}

28. Admin: clear login and OTP lockouts

POST /api/v1/admin/users/{id}/unlock
curl -X 'POST' \
  'http://localhost:8080/api/v1/admin/users/6c5078d3-f8e3-4c88-9afe-48b5423c664f/unlock' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <admin_token>'

Response

{
  "message": "Operation completed"
}

29. List API keys

GET /api/v1/api-keys
curl -X 'GET' \
  'http://localhost:8080/api/v1/api-keys' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>'

Response

[
  {
    "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
    "name": "Example",
    "prefix": "string",
    "scopes": [
      "string"
    ],
    "isActive": true,
    "lastUsedAt": "2024-05-06T12:00:00",
    "expiresAt": "2024-05-06T12:00:00",
    "createdAt": "2024-05-06T12:00:00"
  }
]

30. Create API key

POST /api/v1/api-keys
curl -X 'POST' \
  'http://localhost:8080/api/v1/api-keys' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>' \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "Example",
  "scopes": [
    "string"
  ],
  "expiresAt": "2024-05-06T12:00:00"
}'

Response

{
  "id": "6c5078d3-f8e3-4c88-9afe-48b5423c664f",
  "name": "Example",
  "prefix": "string",
  "scopes": [
    "string"
  ],
  "key": "pending-orders",
  "createdAt": "2024-05-06T12:00:00"
}

31. Revoke API key

DELETE /api/v1/api-keys/{id}
curl -X 'DELETE' \
  'http://localhost:8080/api/v1/api-keys/6c5078d3-f8e3-4c88-9afe-48b5423c664f' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer <access_token>'

Response

{
  "message": "Operation completed"
}

Error Handling

This API follows industry-standard error handling patterns (Stripe, GitHub, OpenAI):

Success Responses

  • HTTP status code indicates success (200, 201, 204)
  • Response body contains data directly (no wrapper object)
  • No isSuccess or statusCode fields needed

Error Responses

Standard Error (400/401/403/404/500):

{
  "message": "Error description"
}

Validation Error (400):

{
  "message": "Validation failed",
  "errors": [
    {"field": "email", "message": "Invalid email format"},
    {"field": "password", "message": "Password must be at least 8 characters with uppercase, lowercase, digit, and special character"}
  ]
}

Common Error Codes

Status Code Description Example Message
400 Bad Request "Invalid email or password"
401 Unauthorized "Authentication required"
403 Forbidden "Insufficient permissions"
404 Not Found "Product not found"
409 Conflict "User already exists with this email"
429 Too Many Requests "Rate limit exceeded. Try again later."
500 Internal Server Error "Internal server error"

All error messages are centralized and consistent across all endpoints.


Security Features

Rate Limiting

Auth endpoints (login, register, forgot-password, reset-password) are rate-limited to 5 requests per 10 minutes per IP address. Exceeding this limit returns a 429 Too Many Requests response.

Account Lockout

After 5 consecutive failed login attempts, the account is automatically locked for 30 minutes. The login response includes remaining attempts count until the lockout is triggered.

Password Strength

All passwords must meet the following criteria: - Minimum 8 characters - At least one uppercase letter - At least one lowercase letter - At least one digit - At least one special character

Multi-Factor Authentication (TOTP)

  • RFC 6238 TOTP with SHA-1, 6 digits and a 30-second period
  • One time step of clock drift is accepted in either direction
  • The secret is generated server-side and stored AES-GCM encrypted (MFA_ENCRYPTION_KEY, falling back to JWT_SECRET in development); enable/disable requires a valid code
  • A TOTP time step can only be used once, preventing code replay within the 30-second window
  • When MFA is enabled, login must include mfaCode
  • Missing code returns 401 MFA_REQUIRED; an incorrect code returns 401 INVALID_MFA_CODE
  • Failed MFA attempts count toward the same 5-attempt lockout as bad passwords

Refresh Token Security

  • Refresh tokens are hashed before storage (SHA-256)
  • Tokens expire after 7 days
  • Each token refresh automatically revokes the old token and issues a new pair
  • Logout revokes all user refresh tokens

Administrative User Management Guidelines

Role Management

  • Admin endpoints require both an ADMIN account and the relevant permission.
  • User type changes update the linked platform role assignment.
  • Deactivated users cannot log in but their data remains intact.
  • Activation restores account access; roles remain assigned.
  • Role and permission management lives under /api/v1/admin/rbac/*; see RBAC.

Security Considerations

  • Changing user types should be done carefully to maintain system security
  • Deactivation should be used for temporary account suspension
  • Regular monitoring of user type changes helps maintain security

API Keys

API keys are scoped to a subset of the owner's effective permissions and are shown once at creation. Send them as Authorization: Bearer ek_....

Method Endpoint Description
GET /api/v1/api-keys List your API keys (metadata only)
POST /api/v1/api-keys Create a key (name, optional scopes, expiresAt)
DELETE /api/v1/api-keys/{id} Revoke a key

Scopes accept permission codes (order:manage, inventory:manage) or legacy enum names (ORDER_MANAGE, INVENTORY_MANAGE). Keys are re-checked against the owner's current effective permissions at authentication, so a role change narrows an existing key.

Feature flags require feature_flag:manage; see RBAC.