Skip to main content

Authentication

The Authentication API allows you to register users, authenticate, and manage access tokens.

Overview​

Linktor supports multiple authentication methods:

  • API Keys: Long-lived tokens for server-to-server integrations
  • JWT Tokens: Short-lived tokens for user sessions
  • OAuth 2.0: For third-party application integrations

Endpoints​

MethodEndpointDescription
POST/auth/registerRegister a new user account
POST/auth/loginAuthenticate and get tokens
POST/auth/refreshRefresh an expired access token
POST/auth/logoutRevoke tokens
GET/auth/meGet current user info
POST/auth/password/resetRequest password reset
POST/auth/password/confirmConfirm password reset

Register​

Create a new user account.

POST /auth/register

Request Body​

FieldTypeRequiredDescription
emailstringYesUser's email address
passwordstringYesPassword (min 8 characters)
namestringYesUser's display name
organizationNamestringNoOrganization name (creates new org)

Example Request​

curl -X POST https://api.linktor.io/v1/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "securepassword123",
"name": "John Doe",
"organizationName": "Acme Corp"
}'

Response​

{
"data": {
"id": "user_abc123",
"type": "user",
"attributes": {
"email": "john@example.com",
"name": "John Doe",
"emailVerified": false,
"createdAt": "2024-01-15T10:30:00Z"
},
"relationships": {
"organization": {
"id": "org_xyz789",
"name": "Acme Corp"
}
}
},
"meta": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "rt_abc123def456",
"expiresIn": 3600
}
}

Error Codes​

HTTP StatusError CodeDescription
400VALIDATION_ERRORInvalid email format or weak password
409EMAIL_ALREADY_EXISTSEmail is already registered

Login​

Authenticate a user and receive access tokens.

POST /auth/login

Request Body​

FieldTypeRequiredDescription
emailstringYesUser's email address
passwordstringYesUser's password
rememberMebooleanNoExtend token expiry (default: false)

Example Request​

curl -X POST https://api.linktor.io/v1/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "securepassword123",
"rememberMe": true
}'

Response​

{
"data": {
"id": "user_abc123",
"type": "user",
"attributes": {
"email": "john@example.com",
"name": "John Doe",
"emailVerified": true,
"lastLoginAt": "2024-01-15T10:30:00Z"
},
"relationships": {
"organization": {
"id": "org_xyz789",
"name": "Acme Corp"
}
}
},
"meta": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "rt_abc123def456",
"expiresIn": 3600,
"tokenType": "Bearer"
}
}

Error Codes​

HTTP StatusError CodeDescription
400VALIDATION_ERRORMissing or invalid fields
401INVALID_CREDENTIALSEmail or password is incorrect
403ACCOUNT_LOCKEDAccount locked due to too many attempts
403EMAIL_NOT_VERIFIEDEmail verification required

Refresh Token​

Exchange a refresh token for a new access token.

POST /auth/refresh

Request Body​

FieldTypeRequiredDescription
refreshTokenstringYesValid refresh token

Example Request​

curl -X POST https://api.linktor.io/v1/auth/refresh \
-H "Content-Type: application/json" \
-d '{
"refreshToken": "rt_abc123def456"
}'

Response​

{
"data": {
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "rt_new789ghi012",
"expiresIn": 3600,
"tokenType": "Bearer"
}
}

Error Codes​

HTTP StatusError CodeDescription
400VALIDATION_ERRORMissing refresh token
401INVALID_REFRESH_TOKENRefresh token is invalid or expired
401TOKEN_REVOKEDRefresh token has been revoked

Logout​

Revoke the current access and refresh tokens.

POST /auth/logout

Headers​

HeaderValueRequired
AuthorizationBearer YOUR_ACCESS_TOKENYes

Request Body​

FieldTypeRequiredDescription
refreshTokenstringNoRevoke specific refresh token
allDevicesbooleanNoRevoke all tokens for user

Example Request​

curl -X POST https://api.linktor.io/v1/auth/logout \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"allDevices": false
}'

Response​

{
"data": {
"message": "Successfully logged out"
}
}

Get Current User​

Retrieve the authenticated user's profile.

GET /auth/me

Headers​

HeaderValueRequired
AuthorizationBearer YOUR_ACCESS_TOKENYes

Example Request​

curl https://api.linktor.io/v1/auth/me \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Response​

{
"data": {
"id": "user_abc123",
"type": "user",
"attributes": {
"email": "john@example.com",
"name": "John Doe",
"avatar": "https://cdn.linktor.io/avatars/user_abc123.jpg",
"emailVerified": true,
"createdAt": "2024-01-01T00:00:00Z",
"lastLoginAt": "2024-01-15T10:30:00Z"
},
"relationships": {
"organization": {
"id": "org_xyz789",
"name": "Acme Corp",
"role": "admin"
}
}
}
}

Error Codes​

HTTP StatusError CodeDescription
401AUTHENTICATION_REQUIREDNo token provided
401INVALID_TOKENToken is invalid or expired

Request Password Reset​

Send a password reset email to the user.

POST /auth/password/reset

Request Body​

FieldTypeRequiredDescription
emailstringYesUser's email address

Example Request​

curl -X POST https://api.linktor.io/v1/auth/password/reset \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com"
}'

Response​

{
"data": {
"message": "If an account exists with this email, a password reset link has been sent."
}
}

Note: The response is intentionally vague to prevent email enumeration attacks.


Confirm Password Reset​

Reset the password using a reset token.

POST /auth/password/confirm

Request Body​

FieldTypeRequiredDescription
tokenstringYesPassword reset token from email
passwordstringYesNew password (min 8 characters)

Example Request​

curl -X POST https://api.linktor.io/v1/auth/password/confirm \
-H "Content-Type: application/json" \
-d '{
"token": "reset_token_from_email",
"password": "newsecurepassword456"
}'

Response​

{
"data": {
"message": "Password has been reset successfully"
}
}

Error Codes​

HTTP StatusError CodeDescription
400VALIDATION_ERRORWeak password
400INVALID_RESET_TOKENToken is invalid or expired

API Keys​

API keys are used for server-to-server integrations. Manage them via the dashboard or API.

List API Keys​

curl https://api.linktor.io/v1/api-keys \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Create API Key​

curl -X POST https://api.linktor.io/v1/api-keys \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Production Server",
"permissions": ["messages:read", "messages:write", "conversations:read"],
"expiresAt": "2025-01-01T00:00:00Z"
}'

Response​

{
"data": {
"id": "key_abc123",
"type": "api_key",
"attributes": {
"name": "Production Server",
"key": "lk_live_abc123def456...",
"permissions": ["messages:read", "messages:write", "conversations:read"],
"lastUsedAt": null,
"expiresAt": "2025-01-01T00:00:00Z",
"createdAt": "2024-01-15T10:30:00Z"
}
}
}

Important: The key field is only returned once when the API key is created. Store it securely.

Delete API Key​

curl -X DELETE https://api.linktor.io/v1/api-keys/key_abc123 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Permissions​

API keys can be scoped with specific permissions:

PermissionDescription
messages:readRead messages
messages:writeSend messages
conversations:readRead conversations
conversations:writeCreate/update conversations
channels:readRead channel configurations
channels:writeCreate/update channels
bots:readRead bot configurations
bots:writeCreate/update bots
webhooks:readRead webhook configurations
webhooks:writeCreate/update webhooks
analytics:readRead analytics data
adminFull administrative access

Token Expiration​

Token TypeDefault ExpiryMaximum Expiry
Access Token1 hour24 hours
Refresh Token7 days30 days
API KeyNo expiryCustom
Password Reset Token1 hour1 hour

Security Best Practices​

  1. Store tokens securely: Never expose tokens in client-side code or logs
  2. Use HTTPS: All API calls must use HTTPS
  3. Rotate API keys: Regularly rotate production API keys
  4. Minimal permissions: Grant only necessary permissions to API keys
  5. Monitor usage: Track API key usage for suspicious activity