How permissions work
Assign permissions to a profile
Use the
POST /api/PermisoPerfil/guardar-permisos endpoint to grant specific module actions to a profile. Each permission is a combination of a module key and an action name.Assign the profile to a user
Every user has exactly one profile (
perfilId). When the user logs in, the API reads the profile’s permission set.Permissions are embedded in the JWT
Each granted permission becomes a
permiso claim in the issued token. The API never queries the database again to check permissions during a request — everything is in the token.Permission format
Every permission string follows the pattern:usuario.agregar— create usersperfil.editar— edit profilesmodulo.eliminar— delete modules
Actions
Five actions are defined for every module:| Action | Meaning |
|---|---|
agregar | Create a new record |
editar | Modify an existing record |
eliminar | Delete a record |
consultar | List or search records |
detalle | Retrieve a single record by ID |
Administrator bypass
If a user’s profile hasBitAdministrador = true, the API injects permission claims for all actions on all modules into the JWT at login time. The esAdmin claim is also set to "true".
The permission check short-circuits for admins:
An administrator’s JWT will contain every
permiso claim for every registered module. If new modules are added to the system, the administrator must log out and back in to receive updated permissions in a new token.HTTP responses for authorization failures
| Scenario | HTTP status |
|---|---|
| No token or invalid token | 401 Unauthorized |
| Valid token but missing required permission | 403 Forbidden |
Built-in module permissions
The following table lists every permission string for all built-in modules. Custom modules you create follow the same pattern using theClave field you set when creating them.
| Module | agregar | editar | eliminar | consultar | detalle |
|---|---|---|---|---|---|
modulo | modulo.agregar | modulo.editar | modulo.eliminar | modulo.consultar | modulo.detalle |
perfil | perfil.agregar | perfil.editar | perfil.eliminar | perfil.consultar | perfil.detalle |
permisosperfil | permisosperfil.agregar | permisosperfil.editar | permisosperfil.eliminar | permisosperfil.consultar | permisosperfil.detalle |
usuario | usuario.agregar | usuario.editar | usuario.eliminar | usuario.consultar | usuario.detalle |
principal11 | principal11.agregar | principal11.editar | principal11.eliminar | principal11.consultar | principal11.detalle |
principal12 | principal12.agregar | principal12.editar | principal12.eliminar | principal12.consultar | principal12.detalle |
principal21 | principal21.agregar | principal21.editar | principal21.eliminar | principal21.consultar | principal21.detalle |
principal22 | principal22.agregar | principal22.editar | principal22.eliminar | principal22.consultar | principal22.detalle |
Checking permissions in the JWT
You can verify which permissions a token carries by decoding it. A non-admin user token with profile-level access might include:Related pages
JWT structure
How claims are structured and how to decode the token.
Authentication overview
The full login flow, token lifetime, and 401 handling.