Skip to content

jam.utils.basic_auth

basic_auth

Functions:

Name Description
basic_auth_decode

Decodes basic auth token to login and password.

basic_auth_encode

Encodes the login and password in a basic auth token.

basic_auth_decode

basic_auth_decode(data: str) -> tuple[str, str]

Decodes basic auth token to login and password.

Parameters:

Name Type Description Default
data str

Decoded data

required

Raises:

Type Description
ValueError

If incorrect format

Example

login, password = basic_auth_decode(header) print(login, password) admin qwerty1234

basic_auth_encode

basic_auth_encode(login: str, password: str) -> str

Encodes the login and password in a basic auth token.

Parameters:

Name Type Description Default
login str

Login

required
password str

Password

required
Example
>>> header = basic_auth_encode("admin", "qwerty1234")
>>> print(header)
YWRtaW46cXdlcnR5MTIzNA==