Overview
Core Projects API uses Laravel Sanctum for authentication. Sanctum provides a lightweight authentication system for SPAs (Single Page Applications) and mobile applications. Authentication requires:- Valid employee credentials (email and password)
- Active employee account with assigned cargo (role)
- API token for subsequent requests
Authentication Flow
Login
Authenticate an employee and receive an API token.Endpoint
This endpoint is currently commented out in the routes file. Based on the source code structure, the authentication is primarily handled through web sessions. For API token-based authentication, you’ll need to implement a Sanctum token endpoint.
Request Body
Employee email address (must be a valid email format)
Employee password
Whether to remember the authentication session
Request Example
Response
Response Fields
Using Your Token
Once authenticated, include the token in theAuthorization header of all API requests:
Example Authenticated Request
Get Current User
Retrieve the authenticated employee’s information.Endpoint
Headers
Bearer token obtained from login
Response
Logout
Revoke the current access token and end the session.Endpoint
This endpoint is currently commented out in the routes file. To implement logout functionality, you’ll need to uncomment the route and ensure it revokes the current Sanctum token.
Headers
Bearer token to revoke
Request Example
Response
200 Success
Token Management
Token Expiration
By default, Sanctum tokens do not expire. The expiration is controlled in theconfig/sanctum.php file:
Token Abilities
Sanctum supports token abilities (permissions). The Empleado model includes theHasApiTokens trait which enables this functionality:
Multiple Tokens
Employees can have multiple active tokens (e.g., for different devices). Each login generates a new token:Role-Based Access Control
The API implements role-based access control through theCheckCargo middleware. Some endpoints require specific roles (cargos):
Common Roles
- Administrador - Full system access
- Gerente - Management access
- Vendedor - Sales operations
- Contador - Accounting operations
If you attempt to access an endpoint without the required role, you’ll receive a
403 Forbidden response with the message: “No tienes permiso para acceder a esta sección.”Authentication Errors
401 Unauthenticated
Returned when no valid token is provided:- Missing
Authorizationheader - Invalid or expired token
- Token format incorrect (must be
Bearer {token})
403 Forbidden
Returned when the authenticated user lacks permission:- User’s cargo (role) doesn’t have access to the endpoint
- Employee account is inactive
- Employee has no cargo assigned
422 Validation Failed
Returned when login credentials fail validation:Security Best Practices
Token Storage
Store tokens securely on the client side. Never expose tokens in URLs or client-side code repositories.
HTTPS Only
Always use HTTPS in production to prevent token interception.
Token Rotation
Implement token rotation by logging out and logging in again periodically.
Scope Tokens
Use token abilities to limit what each token can access when possible.
Next Steps
Now that you’re authenticated, explore the available API endpoints:Projects
Manage construction projects
Apartments
Manage apartments, locales, and parking
Sales
Handle sales operations
Employees
Manage employee records