Authz#
Source code in:
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_parser
argument 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.
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_parser
is 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.
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_AUTHZ
simplify 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_AUTHZ
reduces development overhead.