Module cartridge.auth
Administrators authentication and authorization.
Local Functions
set_enabled (enabled) | Allow or deny unauthenticated access to the administrator's page. |
get_enabled () | Check if unauthenticated access is forbidden. |
init () | Initialize the authentication HTTP API. |
set_callbacks (callbacks) | Set authentication callbacks. |
get_callbacks () | Get authentication callbacks. |
Configuration
set_params (opts) | Modify authentication params. |
get_params () | Retrieve authentication params. |
AuthParams | Authentication params. |
Authorizarion
get_session_username () | Get username for the current HTTP session. |
check_request (req) | Authorize an HTTP request. |
User management
UserInfo | User information. |
add_user (username, password, fullname, email) | Trigger registered add_user callback. |
get_user (username) | Trigger registered get_user callback. |
edit_user (username, password, fullname, email) | Trigger registered edit_user callback. |
list_users () | Trigger registered list_users callback. |
remove_user (username) | Trigger registered remove_user callback. |
Local Functions
- set_enabled (enabled)
-
Allow or deny unauthenticated access to the administrator's page.
(Changed in v0.11)
This function affects only the current instance. It can't be used after the cluster was bootstrapped. To modify clusterwide config use set_params instead.
Parameters:
- enabled boolean
Returns:
-
boolean
true
Or
- nil
- table Error description
- get_enabled ()
-
Check if unauthenticated access is forbidden.
(Added in v0.7)
Returns:
-
boolean
enabled
- init ()
-
Initialize the authentication HTTP API.
Set up
login
andlogout
HTTP endpoints. - set_callbacks (callbacks)
-
Set authentication callbacks.
Parameters:
- callbacks
- add_user function
- get_user function
- edit_user function
- list_users function
- remove_user function
- check_password function
Returns:
-
boolean
true
- callbacks
- get_callbacks ()
-
Get authentication callbacks.
Returns:
-
table
callbacks
Configuration
- set_params (opts)
-
Modify authentication params.
(Changed in v0.11)
Can't be used before the bootstrap. Affects all cluster instances. Triggers
cluster.config_patch_clusterwide
.Parameters:
- opts
- enabled optional boolean (Added in v0.11)
- cookie_max_age optional number
- cookie_renew_age optional number (Added in v0.11)
Returns:
-
boolean
true
Or
- nil
- table Error description
- opts
- get_params ()
-
Retrieve authentication params.
Returns:
- AuthParams
-
Authentication params.
Fields:
- enabled boolean Wether unauthenticated access is forbidden
- cookie_max_age number Number of seconds until the authentication cookie expires
- cookie_renew_age number Update provided cookie if it's older then this age (in seconds)
Authorizarion
- get_session_username ()
-
Get username for the current HTTP session.
Returns:
-
string
or nil if no user is logged in
- check_request (req)
-
Authorize an HTTP request.
Try to get username from cookies or basic HTTP authentication.
Parameters:
- req An HTTP request
Returns:
- boolean Access granted
- table HTTP response template
User management
- UserInfo
-
User information.
Fields:
- add_user (username, password, fullname, email)
-
Trigger registered add_user callback.
The callback is triggered with the same arguments and must return a table with fields conforming to UserInfo. Unknown fields are ignored.
Parameters:
Returns:
Or
- nil
- table Error description
- get_user (username)
-
Trigger registered get_user callback.
The callback is triggered with the same arguments and must return a table with fields conforming to UserInfo. Unknown fields are ignored.
Parameters:
- username string
Returns:
Or
- nil
- table Error description
- edit_user (username, password, fullname, email)
-
Trigger registered edit_user callback.
The callback is triggered with the same arguments and must return a table with fields conforming to UserInfo. Unknown fields are ignored.
Parameters:
Returns:
Or
- nil
- table Error description
- list_users ()
-
Trigger registered list_users callback.
The callback is triggered without any arguments. It must return an array of UserInfo objects.
Returns:
Or
- nil
- table Error description
- remove_user (username)
-
Trigger registered remove_user callback.
The callback is triggered with the same arguments and must return a table with fields conforming to UserInfo, which was removed. Unknown fields are ignored.
Parameters:
- username string
Returns:
Or
- nil
- table Error description