bartender.user#

Classes#

User

User model.

JwtDecoder

JWT decoder.

Functions#

generate_token_subcommand(→ None)

Generate a JSON Web Token (JWT) with the given parameters.

generate_token(→ str)

Generate a JSON Web Token (JWT).

Module Contents#

class bartender.user.User#

Bases: pydantic.BaseModel

User model.

username: str#
roles: Sequence[str] = []#
apikey: str#
class bartender.user.JwtDecoder(key: jose.backends.base.Key)#

JWT decoder.

Parameters:

key (jose.backends.base.Key) – The key to use for decoding the JWT token.

key#
__call__(apikey: str) User#

Decodes a JWT token and returns a User object.

Raises an JOSE exception if the token is invalid.

Parameters:

apikey (str) – The JWT token to decode.

Returns:

A User object.

Return type:

User

classmethod from_file(public_key: pathlib.Path) JwtDecoder#

Create a JwtDecoder from a public key file.

Parameters:

public_key (pathlib.Path) – Path to the public key file.

Returns:

A JwtDecoder object.

Return type:

JwtDecoder

classmethod from_bytes(public_key: bytes) JwtDecoder#

Create a JwtDecoder from a public key.

Parameters:

public_key (bytes) – The public key.

Returns:

A JwtDecoder object.

Return type:

JwtDecoder

bartender.user.generate_token_subcommand(private_key: pathlib.Path, username: str, roles: list[str], lifetime: int, issuer: str, oformat: Literal['header', 'plain'] = 'plain') None#

Generate a JSON Web Token (JWT) with the given parameters.

Parameters:
  • private_key (pathlib.Path) – Path to the private key file.

  • username (str) – The username to include in the token.

  • roles (list[str]) – A list of roles to include in the token.

  • lifetime (int) – The lifetime of the token in minutes.

  • issuer (str) – The issuer of the token.

  • oformat (Literal['header', 'plain']) – The format of the token output. Can be “header” or “plain”.

Returns:

None

Return type:

None

bartender.user.generate_token(private_key: bytes, username: str, roles: list[str], expire: datetime.datetime, issuer: str) str#

Generate a JSON Web Token (JWT).

Parameters:
  • private_key (bytes) – The private key to use for signing the token.

  • username (str) – The username to include in the token.

  • roles (list[str]) – A list of roles to include in the token.

  • expire (datetime.datetime) – When token expires.

  • issuer (str) – The issuer of the token.

Returns:

The generated token.

Return type:

str