apicrud.SessionAuth¶
-
class
apicrud.
SessionAuth
(roles_from=None)¶ Session Authorization
Functions for login, password and role authorization
- Parameters
roles_from (obj) – model for which to look up authorizations
-
__init__
(roles_from=None)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
([roles_from])Initialize self.
account_add
(username, uid)Add an account with the given username
account_login
(username, password[, method, otp])Log in using local or OAuth2 credentials
Get authorization info
get_roles
(uid[, member_model, resource, id])Get roles that match uid / id for a resource Each is in the form <resource>-<id>-<privacy level>
methods
()Return list of available auth methods
totp_bypass
(uid)Check for bypass cookie
update_auth
(id[, member_model, resource, force])Check current access, update if recently changed
-
account_add
(username, uid)¶ Add an account with the given username
- Parameters
username (str) – new / unique username
uid (str) – existing user
-
account_login
(username, password, method='local', otp=None)¶ Log in using local or OAuth2 credentials
- Parameters
username (str) – account name or email
password (str) – credential
method (str) – local, or google / facebook / twitter etc
otp (str) – one-time or backup password
- Returns
Fields include jwt_token (contains uid / account ID), ID of entry in settings database, and a sub-dictionary with mapping of endpoints registered to microservices
- Return type
dict
-
auth_params
()¶ Get authorization info
-
get_roles
(uid, member_model=None, resource=None, id=None)¶ Get roles that match uid / id for a resource Each is in the form <resource>-<id>-<privacy level>
- Parameters
uid (str) – User ID
member_model (str) – resource-name of DB model that defines membership in resource
resource (str) – the resource that defines privacy (e.g. list)
id (str) – ID of the resource (omit if all are desired)
- Returns
authorized roles
- Return type
list of str
-
methods
()¶ Return list of available auth methods
-
totp_bypass
(uid)¶ Check for bypass cookie
- Parameters
uid (str) – User ID
- Returns
valid bypass found
- Return type
bool
-
update_auth
(id, member_model=None, resource=None, force=False)¶ Check current access, update if recently changed
- Parameters
id (str) – resource id of parent resource
resource (str) – parent resource for which membership should be checked
force (bool) – perform update regardless of logged-in permissions