Source code in:
Authentication and Authorization in Yuneta¶
Authentication and authorization in Yuneta ensure secure identification of users and
validation of their permissions to access resources or perform actions.
These processes are managed via APIs such as gobj_authenticate
and gobj_user_has_authz, with the ability to use custom or
built-in parsers and checkers.
Core Concepts¶
1. Authentication¶
Authentication verifies the identity of a user by validating credentials such as tokens or other identifiers.
API:
json_t *gobj_authenticate(hgobj gobj, json_t *kw, hgobj src)Parser: Defined in the
global_authentication_parserargument ofgobj_start_up(). If null, a default parser is used.
The authentication parser:
Processes the credentials provided in
kw.Returns a JSON response indicating success or failure.
2. Authorization¶
Authorization ensures that an authenticated user has the necessary permissions to perform an action or access a resource.
API:
BOOL gobj_user_has_authz(hgobj gobj_to_check, const char *authz, json_t *kw, hgobj src)Checker: Defined in the
global_authorization_checkerargument ofgobj_start_up(). If null, a default checker is used.
The authorization checker:
Uses the
mt_authz_checkermethod if defined in the GClass.Verifies if the user has the required permission (
authz) based on roles and parameters.Returns
TRUEif the user is authorized; otherwise,FALSE.
GClass C_AUTHZ¶
Yuneta provides a GClass C_AUTHZ with default implementations for authentication and authorization:
Authentication:
PUBLIC json_t *authenticate_parser(hgobj gobj_service, json_t *kw, hgobj src)Authorization:
PUBLIC BOOL authz_checker(hgobj gobj_to_check, const char *authz, json_t *kw, hgobj src)
These functions can be used directly by passing them to gobj_start_up().
Workflow¶
Authentication Workflow¶
Request Authentication:
Call
gobj_authenticate()with user credentials inkw.
Parser Selection:
If the GClass defines
mt_authenticate, it is called.Otherwise, the
global_authentication_parseris used.If no parser is provided, the default mechanism is used.
Validation:
Credentials are validated, possibly using external systems (e.g., OAuth2, JWT).
Response:
A JSON response indicates authentication success or failure.
Authorization Workflow¶
Request Authorization:
Call
gobj_user_has_authz()with the required permission (authz).
Checker Selection:
If the GClass defines
mt_authz_checker, it is called.Otherwise, the
global_authorization_checkeris used.If no checker is provided, the default mechanism is used.
Validation:
The checker evaluates the user’s roles and permissions against the required
authz.
Response:
The method returns
TRUEif authorized orFALSEotherwise.
Features¶
Authentication¶
Support for JWT tokens, OAuth2, and system users.
Integration with external identity providers for secure token validation.
Authorization¶
Role-based access control (RBAC) for granular permission management.
Hierarchical roles and services enable complex access control scenarios.
Integration with GObjs¶
Authentication and authorization can be defined per GObj or applied globally.
Built-in methods in
C_AUTHZsimplify implementation.
Benefits¶
Flexibility: Custom parsers and checkers enable tailored authentication and authorization logic.
Security: Centralized access controls ensure consistency and reliability.
Simplicity: Built-in functionality in
C_AUTHZreduces development overhead.