This document provides detailed information about the RBAC System API.
All API endpoints are relative to the base URL:
http://localhost:5000/api
The API uses JWT (JSON Web Tokens) for authentication. Most endpoints require a valid token.
POST /auth/register
Creates a new user account.
Request Body:
{
"username": "johndoe",
"email": "john.doe@example.com",
"password": "securePassword123",
"firstName": "John",
"lastName": "Doe",
"organizationIds": ["60d21b4667d0d8992e610c85"] // Optional
}Response:
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
}
}POST /auth/login
Authenticates a user and returns a JWT token.
Request Body:
{
"username": "johndoe",
"password": "securePassword123"
}Response:
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z",
"lastLogin": "2023-05-03T15:30:00Z"
}
}POST /auth/refresh-token
Refreshes an existing JWT token.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"user": {
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z",
"lastLogin": "2023-05-03T15:30:00Z"
}
}GET /auth/oauth/google
Initiates the Google OAuth flow.
GET /auth/oauth/google/callback
Handles the Google OAuth callback.
GET /auth/oauth/github
Initiates the GitHub OAuth flow.
GET /auth/oauth/github/callback
Handles the GitHub OAuth callback.
GET /users
Retrieves a list of users with pagination.
Query Parameters:
limit(optional, default: 100): Number of users to returnskip(optional, default: 0): Number of users to skip (for pagination)organizationId(optional): Filter users by organization ID
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"users": [
{
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z",
"lastLogin": "2023-05-03T15:30:00Z"
},
// More users...
],
"total": 125,
"limit": 10,
"skip": 0
}
}GET /users/:id
Retrieves a specific user by ID.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z",
"lastLogin": "2023-05-03T15:30:00Z"
}
}POST /users
Creates a new user.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"username": "johndoe",
"email": "john.doe@example.com",
"password": "securePassword123",
"firstName": "John",
"lastName": "Doe",
"active": true,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local"
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
}
}PUT /users/:id
Updates an existing user.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"firstName": "John",
"lastName": "Doe Updated",
"active": true,
"roleIds": ["60d21b4667d0d8992e610c87", "60d21b4667d0d8992e610c88"],
"organizationIds": ["60d21b4667d0d8992e610c85"]
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c86",
"username": "johndoe",
"email": "john.doe@example.com",
"firstName": "John",
"lastName": "Doe Updated",
"active": true,
"emailVerified": false,
"roleIds": ["60d21b4667d0d8992e610c87", "60d21b4667d0d8992e610c88"],
"organizationIds": ["60d21b4667d0d8992e610c85"],
"authProvider": "local",
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T15:45:00Z",
"lastLogin": "2023-05-03T15:30:00Z"
}
}DELETE /users/:id
Deletes a user.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"message": "User deleted successfully"
}GET /roles
Retrieves a list of roles with pagination.
Query Parameters:
limit(optional, default: 100): Number of roles to returnskip(optional, default: 0): Number of roles to skip (for pagination)organizationId(optional): Filter roles by organization ID
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"roles": [
{
"id": "60d21b4667d0d8992e610c87",
"name": "Admin",
"description": "Administrator role with full access",
"organizationId": "60d21b4667d0d8992e610c85",
"permissionIds": ["60d21b4667d0d8992e610c89", "60d21b4667d0d8992e610c90"],
"isSystemDefault": true,
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
},
// More roles...
],
"total": 5,
"limit": 10,
"skip": 0
}
}GET /roles/:id
Retrieves a specific role by ID.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c87",
"name": "Admin",
"description": "Administrator role with full access",
"organizationId": "60d21b4667d0d8992e610c85",
"permissionIds": ["60d21b4667d0d8992e610c89", "60d21b4667d0d8992e610c90"],
"isSystemDefault": true,
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
}
}POST /roles
Creates a new role.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"name": "Project Manager",
"description": "Manages projects and teams",
"organizationId": "60d21b4667d0d8992e610c85",
"permissionIds": ["60d21b4667d0d8992e610c89"],
"isSystemDefault": false
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c88",
"name": "Project Manager",
"description": "Manages projects and teams",
"organizationId": "60d21b4667d0d8992e610c85",
"permissionIds": ["60d21b4667d0d8992e610c89"],
"isSystemDefault": false,
"createdAt": "2023-05-03T16:00:00Z",
"updatedAt": "2023-05-03T16:00:00Z"
}
}PUT /roles/:id
Updates an existing role.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"name": "Project Manager",
"description": "Manages projects, teams, and resources",
"permissionIds": ["60d21b4667d0d8992e610c89", "60d21b4667d0d8992e610c91"]
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c88",
"name": "Project Manager",
"description": "Manages projects, teams, and resources",
"organizationId": "60d21b4667d0d8992e610c85",
"permissionIds": ["60d21b4667d0d8992e610c89", "60d21b4667d0d8992e610c91"],
"isSystemDefault": false,
"createdAt": "2023-05-03T16:00:00Z",
"updatedAt": "2023-05-03T16:15:00Z"
}
}DELETE /roles/:id
Deletes a role.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"message": "Role deleted successfully"
}PUT /roles/:id/permissions
Updates the permissions assigned to a role.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"permissionIds": ["60d21b4667d0d8992e610c89", "60d21b4667d0d8992e610c90", "60d21b4667d0d8992e610c91"]
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c88",
"name": "Project Manager",
"description": "Manages projects, teams, and resources",
"organizationId": "60d21b4667d0d8992e610c85",
"permissionIds": ["60d21b4667d0d8992e610c89", "60d21b4667d0d8992e610c90", "60d21b4667d0d8992e610c91"],
"isSystemDefault": false,
"createdAt": "2023-05-03T16:00:00Z",
"updatedAt": "2023-05-03T16:30:00Z"
}
}GET /permissions
Retrieves a list of permissions with pagination.
Query Parameters:
limit(optional, default: 100): Number of permissions to returnskip(optional, default: 0): Number of permissions to skip (for pagination)organizationId(optional): Filter permissions by organization IDresource(optional): Filter permissions by resourceaction(optional): Filter permissions by action
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"permissions": [
{
"id": "60d21b4667d0d8992e610c89",
"name": "View Users",
"description": "Can view user information",
"resource": "users",
"action": "read",
"organizationId": null,
"isSystemDefault": true,
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
},
// More permissions...
],
"total": 15,
"limit": 10,
"skip": 0
}
}GET /permissions/:id
Retrieves a specific permission by ID.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c89",
"name": "View Users",
"description": "Can view user information",
"resource": "users",
"action": "read",
"organizationId": null,
"isSystemDefault": true,
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
}
}POST /permissions
Creates a new permission.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"name": "Delete Projects",
"description": "Can delete projects",
"resource": "projects",
"action": "delete",
"organizationId": "60d21b4667d0d8992e610c85",
"isSystemDefault": false
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c92",
"name": "Delete Projects",
"description": "Can delete projects",
"resource": "projects",
"action": "delete",
"organizationId": "60d21b4667d0d8992e610c85",
"isSystemDefault": false,
"createdAt": "2023-05-03T17:00:00Z",
"updatedAt": "2023-05-03T17:00:00Z"
}
}PUT /permissions/:id
Updates an existing permission.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"name": "Delete Projects",
"description": "Can delete projects and associated resources",
"resource": "projects",
"action": "delete"
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c92",
"name": "Delete Projects",
"description": "Can delete projects and associated resources",
"resource": "projects",
"action": "delete",
"organizationId": "60d21b4667d0d8992e610c85",
"isSystemDefault": false,
"createdAt": "2023-05-03T17:00:00Z",
"updatedAt": "2023-05-03T17:15:00Z"
}
}DELETE /permissions/:id
Deletes a permission.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"message": "Permission deleted successfully"
}GET /organizations
Retrieves a list of organizations with pagination.
Query Parameters:
limit(optional, default: 100): Number of organizations to returnskip(optional, default: 0): Number of organizations to skip (for pagination)
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"organizations": [
{
"id": "60d21b4667d0d8992e610c85",
"name": "Acme Corp",
"description": "Leading widgets manufacturer",
"domain": "acme.com",
"active": true,
"adminIds": ["60d21b4667d0d8992e610c86"],
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
},
// More organizations...
],
"total": 3,
"limit": 10,
"skip": 0
}
}GET /organizations/:id
Retrieves a specific organization by ID.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c85",
"name": "Acme Corp",
"description": "Leading widgets manufacturer",
"domain": "acme.com",
"active": true,
"adminIds": ["60d21b4667d0d8992e610c86"],
"createdAt": "2023-05-03T12:00:00Z",
"updatedAt": "2023-05-03T12:00:00Z"
}
}POST /organizations
Creates a new organization.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"name": "Globex Corporation",
"description": "International technology company",
"domain": "globex.com",
"active": true,
"adminIds": ["60d21b4667d0d8992e610c86"]
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c93",
"name": "Globex Corporation",
"description": "International technology company",
"domain": "globex.com",
"active": true,
"adminIds": ["60d21b4667d0d8992e610c86"],
"createdAt": "2023-05-03T18:00:00Z",
"updatedAt": "2023-05-03T18:00:00Z"
}
}PUT /organizations/:id
Updates an existing organization.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Request Body:
{
"name": "Globex Corporation",
"description": "International technology and innovation company",
"domain": "globex.com",
"active": true,
"adminIds": ["60d21b4667d0d8992e610c86", "60d21b4667d0d8992e610c94"]
}Response:
{
"success": true,
"data": {
"id": "60d21b4667d0d8992e610c93",
"name": "Globex Corporation",
"description": "International technology and innovation company",
"domain": "globex.com",
"active": true,
"adminIds": ["60d21b4667d0d8992e610c86", "60d21b4667d0d8992e610c94"],
"createdAt": "2023-05-03T18:00:00Z",
"updatedAt": "2023-05-03T18:15:00Z"
}
}DELETE /organizations/:id
Deletes an organization.
Headers:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Response:
{
"success": true,
"message": "Organization deleted successfully"
}The API uses consistent error responses across all endpoints.
{
"success": false,
"error": "Error message describing what went wrong"
}200 OK: Request succeeded201 Created: Resource created successfully400 Bad Request: Invalid request parameters401 Unauthorized: Authentication required or failed403 Forbidden: Permission denied404 Not Found: Resource not found409 Conflict: Resource already exists500 Internal Server Error: Server-side error