Token#

class gafaelfawr.models.token.Token(**data)#

Bases: BaseModel

An opaque token.

Notes

A token consists of two parts, a semi-public key that is used as the Redis key, and a secret that is only present in the token returned to the user and the encrypted session in Redis.

The serialized form of a token always starts with gt-, short for Gafaelfawr token, to make it easier to identify these tokens in logs.

The serialized form encodes the secret in URL-safe base64 with the padding stripped off (because equal signs can be parsed oddly in cookies).

Parameters:

data (Any)

Attributes Summary

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Methods Summary

from_str(token)

Parse a serialized token into a Token.

is_token(token)

Determine if a string is a Gafaelfawr token.

Attributes Documentation

model_config: ClassVar[ConfigDict] = {}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Methods Documentation

classmethod from_str(token)#

Parse a serialized token into a Token.

Parameters:

token (str) – The serialized token.

Returns:

The decoded Token.

Return type:

Token

Raises:

InvalidTokenError – The provided string is not a valid token.

classmethod is_token(token)#

Determine if a string is a Gafaelfawr token.

Parameters:

token (str) – The string to check.

Returns:

Whether that string looks like a Gafaelfawr token. The token isn’t checked for validity, only format.

Return type:

bool