State

pydantic model gafaelfawr.models.state.State

State information stored in a cookie.

Parameters:

data (Any)

Show JSON schema
{
   "title": "State",
   "description": "State information stored in a cookie.",
   "type": "object",
   "properties": {
      "csrf": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "CSRF token for form submissions",
         "title": "CSRF token"
      },
      "token": {
         "anyOf": [
            {
               "$ref": "#/$defs/Token"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Token if the user is authenticated",
         "title": "Token"
      },
      "github": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "GitHub OAuth token if user authenticated via GitHub",
         "title": "GitHub OAuth token"
      },
      "return_url": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Destination URL after completion of login",
         "title": "Destination after login"
      },
      "state": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "State token for OAuth 2.0 and OpenID Connect logins",
         "title": "Login state"
      },
      "login_start": {
         "anyOf": [
            {
               "format": "date-time",
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Start time of login process if one is in progress",
         "title": "Login start time"
      }
   },
   "$defs": {
      "Token": {
         "description": "An opaque token.\n\nNotes\n-----\nA token consists of two parts, a semi-public key that is used as the Redis\nkey, and a secret that is only present in the token returned to the user\nand the encrypted session in Redis.\n\nThe serialized form of a token always starts with ``gt-``, short for\nGafaelfawr token, to make it easier to identify these tokens in logs.\n\nThe serialized form encodes the secret in URL-safe base64 with the padding\nstripped off (because equal signs can be parsed oddly in cookies).",
         "properties": {
            "key": {
               "title": "Key",
               "type": "string"
            },
            "secret": {
               "title": "Secret",
               "type": "string"
            }
         },
         "title": "Token",
         "type": "object"
      }
   }
}

Fields:
field csrf: Annotated[str | None, Field(title='CSRF token', description='CSRF token for form submissions')] = None

CSRF token for form submissions

field github: Annotated[str | None, Field(title='GitHub OAuth token', description='GitHub OAuth token if user authenticated via GitHub')] = None

GitHub OAuth token if user authenticated via GitHub

field login_start: Annotated[UtcDatetime | None, Field(title='Login start time', description='Start time of login process if one is in progress')] = None

Start time of login process if one is in progress

field return_url: Annotated[str | None, Field(title='Destination after login', description='Destination URL after completion of login')] = None

Destination URL after completion of login

field state: Annotated[str | None, Field(title='Login state', description='State token for OAuth 2.0 and OpenID Connect logins')] = None

State token for OAuth 2.0 and OpenID Connect logins

field token: Annotated[Token | None, BeforeValidator(lambda t: Token.from_str(t) if isinstance(t, str) else t), PlainSerializer(lambda t: str(t)), Field(title='Token', description='Token if the user is authenticated')] = None

Token if the user is authenticated

Constraints:
  • func = <function <lambda> at 0x7f2f2ef77880>

  • json_schema_input_type = PydanticUndefined

  • return_type = PydanticUndefined

  • when_used = always

Reconstruct state from an encrypted cookie.

Parameters:
  • cookie (str) – The encrypted cookie value.

  • key – The Fernet key used to decrypt it.

  • request (Request | None, default: None) – The request, used for logging. If not provided (primarily for the test suite), invalid state cookies will not be logged.

Returns:

The state represented by the cookie.

Return type:

State

Build an encrypted cookie representation of the state.

Returns:

The encrypted cookie value.

Return type:

str