-
Notifications
You must be signed in to change notification settings - Fork 5
Multi‐Tenant System API Documentation
ybw0014 edited this page Apr 4, 2024
·
7 revisions
This document provides an overview and detailed description of the essential APIs for a multi-tenant system. These APIs cover the management of tenants, users, permissions, and authentication processes, following RESTful principles, secure practices, and clear error handling.
All the standard HTTP REST API endpoints return the following response:
{
"code": "number", // 0 = success, other = failed
"message": "string", // the message that illustrates what is wrong
"data": "object" // the response data. will be `null` when the request is failed, or contains extra error information.
}
For gRPC requests, the response data becomes the object being returned when the request is successful. Otherwise, a gRPC runtime error will be returned.
-
Endpoint:
/api/v1/tenants -
Method:
POST - Description: Allows a new user to register and create a new tenant.
- Authentication: No authentication required.
- Request Body:
{
"name": "string",
"adminEmail": "string",
"businessTypeId": "number"
}
-
Response:
-
Status:
201 Created - Response data object:
-
Status:
{
"id": "number",
"adminUser": {
"id": "number",
"email": "string",
"password": "string"
}
}
-
Endpoint:
/api/v1/tenants/{id} -
Method:
GET - Description: Provides detailed information about a specific tenant.
- Authentication: No authentication required.
-
Response:
-
Status:
200 OK - Response data object:
-
Status:
{
"id": "string",
"name": "string",
"businessTypeId": "number",
"createdAt": "datetime",
"updatedAt": "datetime"
}
-
Endpoint:
/api/v1/tenants/{id} -
Method:
PATCH - Description: Updates information of a tenant.
-
Authentication: Permission
tenant:updateis required. - Request Body:
{
"name": "string",
"businessTypeId": "number"
}
-
Response:
-
Status:
200 OK
-
Status:
-
Endpoint:
/api/v1/users -
Method:
POST - Description: Registers a new user in the system.
- Authentication: No authentication required.
- Request Body:
{
"email": "string",
"name": "string",
"password": "string",
"tenantId": "number"
}
-
Response:
-
Status:
201 Created - Response data object:
-
Status:
{
"id": "number"
}
-
Endpoint:
/api/v1/users/login -
Method:
POST - Description: User login to obtain access token.
- Authentication: No authentication required.
- Request Body:
{
"email": "string",
"password": "string",
"tenantId": "number"
}
-
Response:
-
Status:
200 OK - Response data object:
-
Status:
{
"id": "number",
"tenantId": "number",
"accessToken": {
"token": "string",
"type": "string",
"expiresAt": "datetime"
},
"refershToken": {
"token": "string",
"expiresAt": "datetime"
}
}
-
Endpoint:
/api/v1/tenants/{id}/users -
Method:
GET - Description: Retrieves a list of all users within a tenant.
-
Authentication: Permission
tenant:list_usersis required. -
Response:
-
Status:
200 OK - Response data object:
-
Status:
[
{
"userId": "string",
"email": "string",
"name": "string",
...
},
...
]
-
Endpoint:
/api/v1/roles -
Method:
GET - Description: Retrieves a list of all roles defined in the system.
- Authentication: No authentication required.
-
Response:
-
Status:
200 OK - Response data object:
-
Status:
["role1", "role2", ...]
-
Endpoint:
/api/v1/users/{userId}/roles -
Method:
POST - Description: Assigns roles to a specific user.
-
Authentication: Permission
tenant:manage_usersis required. - Request Body:
{
"roles": ["role1", "role2", ...]
}
-
Response:
-
Status:
200 OK
-
Status:
-
Endpoint:
/api/v1/auth/validate -
Method:
POST - Description: Validates a user's access token.
- Authentication: No authentication required.
- Request Body:
{
"token": "string"
}
-
Response when token is valid:
-
Status:
200 OK - Response data object:
-
Status:
{
"userId": "string"
}
-
Response when token is invalid:
-
Status:
401 Unauthorized
-
Status: