Skip to main content

SecureCookieSessionInterface

The default session interface that stores sessions in signed cookies through the :mod:itsdangerous module.

Attributes

AttributeTypeDescription
salt= cookie-sessionThe salt that should be applied on top of the secret key for the signing of cookie based sessions.
digest_method= staticmethod(_lazy_sha1)The hash function to use for the signature, defaulting to sha1.
key_derivation= hmacThe name of the itsdangerous supported key derivation, defaulting to hmac.
serializer= session_json_serializerA Python serializer for the payload, defaulting to a compact JSON derived serializer with support for extra Python types.
session_class= SecureCookieSessionThe class used to represent the session, which is SecureCookieSession.

Methods


get_signing_serializer()

@classmethod
def get_signing_serializer(
app: [Flask](../app/flask.md?sid=flask_app_flask)
) - > URLSafeTimedSerializer | None

Retrieves the signing serializer for the application. This serializer is used to sign and unsign session cookies, ensuring their integrity and authenticity.

Parameters

NameTypeDescription
app[Flask](../app/flask.md?sid=flask_app_flask)The Flask application instance, used to access configuration like the secret key.

Returns

TypeDescription
`URLSafeTimedSerializerNone`

open_session()

@classmethod
def open_session(
app: [Flask](../app/flask.md?sid=flask_app_flask),
request: [Request](../wrappers/request.md?sid=flask_wrappers_request)
) - > SecureCookieSession | None

Opens and loads a session from the incoming request's cookies. It deserializes the session data using the signing serializer and returns a SecureCookieSession object.

Parameters

NameTypeDescription
app[Flask](../app/flask.md?sid=flask_app_flask)The Flask application instance, used to retrieve the signing serializer and cookie name.
request[Request](../wrappers/request.md?sid=flask_wrappers_request)The incoming request object, from which the session cookie is read.

Returns

TypeDescription
`SecureCookieSessionNone`

save_session()

@classmethod
def save_session(
app: [Flask](../app/flask.md?sid=flask_app_flask),
session: [SessionMixin](sessionmixin.md?sid=flask_sessions_sessionmixin),
response: [Response](../wrappers/response.md?sid=flask_wrappers_response)
) - > None

Saves the current session to the outgoing response's cookies. It serializes the session data, signs it, and sets the appropriate cookie headers on the response.

Parameters

NameTypeDescription
app[Flask](../app/flask.md?sid=flask_app_flask)The Flask application instance, used to retrieve cookie configuration and the signing serializer.
session[SessionMixin](sessionmixin.md?sid=flask_sessions_sessionmixin)The session object to be saved. If the session is empty and modified, its cookie will be deleted.
response[Response](../wrappers/response.md?sid=flask_wrappers_response)The outgoing response object, where the session cookie will be set or deleted.

Returns

TypeDescription
NoneThis method does not return any value; it modifies the response object by setting or deleting a cookie.