Skip to main content

Overview

GIMA uses Laravel Sanctum for API authentication with token-based access control. All protected endpoints require a Bearer token in the Authorization header.

Authentication Flow

1

Register a new user

Create a new user account by providing name, email, and password.
2

Login to get access token

Submit credentials to receive a Bearer token for API access.
3

Include token in requests

Add the token to the Authorization header for all protected endpoints.
4

Access profile information

Retrieve your user profile and assigned roles.

Register New User

Create a new user account in the GIMA system.

Endpoint

POST /api/autenticacion/registrar

Request Body

name
string
required
Full name of the user (max 255 characters)
email
string
required
Valid email address (must be unique in the system)
password
string
required
Password (minimum 8 characters)
password_confirmation
string
required
Must match the password field

Example Request

curl -X POST http://127.0.0.1:8000/api/autenticacion/registrar \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "name": "Usuario Prueba",
    "email": "[email protected]",
    "password": "secret123",
    "password_confirmation": "secret123"
  }'

Response

{
  "estado": "exito",
  "mensaje": "Usuario registrado correctamente",
  "data": {
    "usuario": "Usuario Prueba",
    "email": "[email protected]"
  }
}
Newly registered users have no roles assigned by default. An administrator must assign roles (admin, tecnico, supervisor, reporter) through the role management system.

Login

Authenticate with your credentials to receive an access token.

Endpoint

POST /api/autenticacion/iniciar-sesion

Request Body

email
string
required
Registered email address
password
string
required
User password

Example Request

curl -X POST http://127.0.0.1:8000/api/autenticacion/iniciar-sesion \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "12345678"
  }'

Response

{
  "estado": "exito",
  "mensaje": "Login correcto",
  "data": {
    "usuario": "Admin User",
    "roles": ["admin"],
    "token": "1|abcdefghijklmnopqrstuvwxyz1234567890"
  }
}
Store the access token securely. It provides full access to your account and should never be exposed in client-side code or version control.

Get User Profile

Retrieve the authenticated user’s profile information and assigned roles.

Endpoint

GET /api/autenticacion/perfil

Headers

Authorization
string
required
Bearer token obtained from loginFormat: Bearer {token}

Example Request

curl -X GET http://127.0.0.1:8000/api/autenticacion/perfil \
  -H "Authorization: Bearer 1|abcdefghijklmnopqrstuvwxyz1234567890" \
  -H "Accept: application/json"

Response

200 Success
{
  "estado": "exito",
  "data": {
    "id": 1,
    "name": "Admin User",
    "email": "[email protected]",
    "email_verified_at": null,
    "created_at": "2024-01-15T10:30:00.000000Z",
    "updated_at": "2024-01-15T10:30:00.000000Z"
  },
  "roles_asignados": ["admin"]
}

User Roles

GIMA implements role-based access control with the following roles:

Available Roles

Role: admin

Permissions:
- Full system access
- User management
- Role assignment
- Access to all protected routes
- Dashboard: /api/admin/dashboard
A user can have multiple roles. For example, a user with both tecnico and supervisor roles has combined permissions from both.

Protected Routes Example

Here’s how to access role-protected endpoints:
# Requires: admin role
curl -X GET http://127.0.0.1:8000/api/admin/dashboard \
  -H "Authorization: Bearer {admin_token}" \
  -H "Accept: application/json"

# Response 200:
# {"mensaje": "Hola Admin, tienes control total."}

# Response 403 (if not admin):
# {"message": "Unauthorized"}

Error Codes

Status CodeDescription
200Success - Request completed successfully
201Created - New user registered
401Unauthorized - Invalid credentials or missing token
403Forbidden - User lacks required role permissions
422Validation Error - Invalid input data

Best Practices

1

Secure token storage

Store tokens securely using HttpOnly cookies or secure storage mechanisms. Never expose tokens in URLs or client-side JavaScript.
2

Handle token expiration

Implement token refresh logic or prompt users to re-authenticate when tokens expire.
3

Use HTTPS in production

Always use HTTPS in production to encrypt authentication credentials and tokens in transit.
4

Implement proper error handling

Handle 401 and 403 errors gracefully by redirecting to login or showing appropriate error messages.

Build docs developers (and LLMs) love