Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions blacksheep/server/authentication/cookie.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ def set_cookie(self, data: Any, response: Response, secure: bool = False) -> Non
"""
Sets the cookie used for authentication. If a cookie is set, it is assumed that
the user is recognized (authenticated). The passed value is serialized, meaning
signed and encrypted using the `itsdangerous.Serializer` associated with this
CookieAuthentication handler. A common scenario is that data is a dictionary
signed (not encrypted) using the `itsdangerous.Serializer` associated with this
CookieAuthentication handler - the cookie value protects against tampering, but
its contents remain readable to anyone with access to the cookie, so it should
not be used to store secrets. A common scenario is that data is a dictionary
with claims describing the identity of the user (e.g. id_token claims).

Parameters
Expand Down
17 changes: 12 additions & 5 deletions blacksheep/server/authentication/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,10 @@ async def get_success_response(
) -> Response:
"""
Returns a redirect response that includes Set-Cookie headers
to configure an encrypted id_token and, optionally, also encrypted
access_token and refresh_token.
to configure a signed (not encrypted) id_token and, optionally, also
signed access_token and refresh_token. The cookie values are protected
against tampering, but remain readable to anyone with access to the
cookie.
"""
response = redirect(original_path)
await self._set_tokens_in_response(request, response, id_token, token_response)
Expand Down Expand Up @@ -588,8 +590,10 @@ async def get_success_response(
) -> Response:
"""
Returns a redirect response that includes Set-Cookie headers
to configure an encrypted id_token and, optionally, also encrypted
access_token and refresh_token.
to configure a signed (not encrypted) id_token and, optionally, also
signed access_token and refresh_token. The cookie values are protected
against tampering, but remain readable to anyone with access to the
cookie.
"""
response = html(
self._get_html(
Expand Down Expand Up @@ -699,7 +703,10 @@ class TokenType(Enum):

class CookiesTokensStore(TokensStore):
"""
A class that can store access and refresh tokens in encrypted form in cookies.
A class that can store access and refresh tokens in cookies, signed (not
encrypted) using `itsdangerous`. The cookie values are protected against
tampering, but remain readable to anyone with access to the cookie - do not
rely on this for confidentiality of the token contents.

Beware that cookies size can be problematic when storing all information in cookies.
If this is the case, consider implementing a type of `BaseTokensStore` that uses
Expand Down