Authentication
elva.auth
Module providing authentication utilities for server
app module.
Classes:
-
BasicAuth
–Base class for
Basic Authentication
. -
DummyAuth
–Dummy
Basic Authentication
class where password equals user name. -
LDAPBasicAuth
–Basic Authentication
using LDAP self-bind.
Functions:
-
basic_authorization_header
–Compose the Base64 encoded
Authorization
header forBasic
authentication. -
process_authorization_header
–Decompose Base64 encoded
Authorization
header into scheme and credentials. -
process_basic_auth_credentials
–Decode Base64 encoded
Basic
authorization header payload. -
abort_basic_auth
–Compose
Basic Authentication
abort information.
Attributes:
-
AUTH_SCHEME
–Valid autentication schemes in
Authorization
HTTP request header.
AUTH_SCHEME = ['Basic', 'Digest', 'Negotiate']
module-attribute
Valid autentication schemes in Authorization
HTTP request header.
BasicAuth(realm)
Base class for Basic Authentication
.
This class is intended to be used in the server
app module.
Parameters:
-
realm
(str
) –realm of the
Basic Authentication
.
Methods:
-
authenticate
–Wrapper around
verify
with processing and logging. -
verify
–Decides whether the given credentials are valid or not.
Source code in src/elva/auth.py
authenticate(path, request_headers)
Wrapper around verify
with processing and logging.
Parameters:
Returns:
-
None | tuple[HTTPStatus, dict[str, str], None | bytes]
–None
ifverify
returnsTrue
, else it returns the request abort information as specified inabort_basic_auth
.
Source code in src/elva/auth.py
verify(username, password)
Decides whether the given credentials are valid or not.
This is defined as a no-op and is intended to implemented in inheriting subclasses.
Parameters:
-
username
(str
) –user name provided in the HTTP request headers.
-
password
(str
) –password provided in the HTTP request headers.
Returns:
-
bool
–True
if credentials are valid,False
if they are not.
Source code in src/elva/auth.py
DummyAuth(realm)
Bases: BasicAuth
Dummy Basic Authentication
class where password equals user name.
Danger
This class is intended for testing only. DO NOT USE IN PRODUCTION!
Source code in src/elva/auth.py
LDAPBasicAuth(realm, server, base)
Bases: BasicAuth
Basic Authentication
using LDAP self-bind.
Parameters:
-
realm
(str
) –realm of the
Basic Authentication
. -
server
(str
) –address of the LDAP server.
-
base
(str
) –base for lookup on the LDAP server.
Methods:
-
verify
–Perform a self-bind connection to the given LDAP server.
Source code in src/elva/auth.py
verify(username, password)
Perform a self-bind connection to the given LDAP server.
Parameters:
-
username
(str
) –user name to use for the LDAP self-bind connection.
-
password
(str
) –password to use for the LDAP self-bind connection.
Returns:
-
bool
–True
if the LDAP self-bind connection could be established, i.e. was successful,False
if no successful connection could be established.
Source code in src/elva/auth.py
basic_authorization_header(username, password)
Compose the Base64 encoded Authorization
header for Basic
authentication.
Parameters:
-
username
(str
) –user name used for authentication.
-
password
(str
) –password used for authentication.
Returns:
Source code in src/elva/auth.py
process_authorization_header(request_headers)
Decompose Base64 encoded Authorization
header into scheme and credentials.
Parameters:
-
request_headers
(dict
) –dictionary of HTTP request headers.
Returns:
Source code in src/elva/auth.py
process_basic_auth_credentials(credentials)
Decode Base64 encoded Basic
authorization header payload.
Parameters:
-
credentials
(str
) –Base64 encoded credentials from the
Authorization
HTTP request header.
Returns:
Source code in src/elva/auth.py
abort_basic_auth(realm, body=None, status=HTTPStatus.UNAUTHORIZED)
Compose Basic Authentication
abort information.
Parameters:
-
realm
(str
) –Basic Authentication
realm. -
body
(None | str
, default:None
) –message body to send.
-
status
(HTTPStatus
, default:UNAUTHORIZED
) –HTTP status for this abort.
Returns:
-
tuple[HTTPStatus, dict[str, str], None | bytes]
–tuple holding the HTTP status, the dictionary with the
WWW-Authenticate
header information forBasic Authentication
and the UTF-8 encoded message body if given.