Skip to content

Commit

Permalink
Add samesite support. (#575)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamsorcerer committed Nov 3, 2021
1 parent 013ad47 commit cc4f6f5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 8 deletions.
8 changes: 6 additions & 2 deletions aiohttp_session/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class _CookieParams(TypedDict, total=False):
path: str
secure: Optional[bool]
httponly: bool
samesite: Optional[str]
expires: str


Expand Down Expand Up @@ -219,6 +220,7 @@ def __init__(
path: str = '/',
secure: Optional[bool] = None,
httponly: bool = True,
samesite: Optional[str] = None,
encoder: Callable[[object], str] = json.dumps,
decoder: Callable[[str], Any] = json.loads
) -> None:
Expand All @@ -228,7 +230,8 @@ def __init__(
max_age=max_age,
path=path,
secure=secure,
httponly=httponly
httponly=httponly,
samesite=samesite
)
self._max_age = max_age
self._encoder = encoder
Expand Down Expand Up @@ -305,12 +308,13 @@ def __init__(
path: str = '/',
secure: Optional[bool] = None,
httponly: bool = True,
samesite: Optional[str] = None,
encoder: Callable[[object], str] = json.dumps,
decoder: Callable[[str], Any] = json.loads
) -> None:
super().__init__(cookie_name=cookie_name, domain=domain,
max_age=max_age, path=path, secure=secure,
httponly=httponly,
httponly=httponly, samesite=samesite,
encoder=encoder, decoder=decoder)

async def load_session(self, request: web.Request) -> Session:
Expand Down
3 changes: 2 additions & 1 deletion aiohttp_session/cookie_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ def __init__(
path: str = '/',
secure: Optional[bool] = None,
httponly: bool = True,
samesite: Optional[str] = None,
encoder: Callable[[object], str] = json.dumps,
decoder: Callable[[str], Any] = json.loads
) -> None:
super().__init__(cookie_name=cookie_name, domain=domain,
max_age=max_age, path=path, secure=secure,
httponly=httponly,
httponly=httponly, samesite=samesite,
encoder=encoder, decoder=decoder)

if isinstance(secret_key, str):
Expand Down
3 changes: 2 additions & 1 deletion aiohttp_session/memcached_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ def __init__( # type: ignore[no-any-unimported] # TODO: aiomcache
path: str = '/',
secure: Optional[bool] = None,
httponly: bool = True,
samesite: Optional[str] = None,
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex,
encoder: Callable[[object], str] = json.dumps,
decoder: Callable[[str], Any] = json.loads
) -> None:
super().__init__(cookie_name=cookie_name, domain=domain,
max_age=max_age, path=path, secure=secure,
httponly=httponly,
httponly=httponly, samesite=samesite,
encoder=encoder, decoder=decoder)
self._key_factory = key_factory
self.conn = memcached_conn
Expand Down
3 changes: 2 additions & 1 deletion aiohttp_session/nacl_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ def __init__(
path: str = '/',
secure: Optional[bool] = None,
httponly: bool = True,
samesite: Optional[str] = None,
encoder: Callable[[object], str] = json.dumps,
decoder: Callable[[str], Any] = json.loads
) -> None:
super().__init__(cookie_name=cookie_name, domain=domain,
max_age=max_age, path=path, secure=secure,
httponly=httponly,
httponly=httponly, samesite=samesite,
encoder=encoder, decoder=decoder)

self._secretbox = nacl.secret.SecretBox(secret_key)
Expand Down
3 changes: 2 additions & 1 deletion aiohttp_session/redis_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ def __init__(
path: str = '/',
secure: Optional[bool] = None,
httponly: bool = True,
samesite: Optional[str] = None,
key_factory: Callable[[], str] = lambda: uuid.uuid4().hex,
encoder: Callable[[object], str] = json.dumps,
decoder: Callable[[str], Any] = json.loads
) -> None:
super().__init__(cookie_name=cookie_name, domain=domain,
max_age=max_age, path=path, secure=secure,
httponly=httponly,
httponly=httponly, samesite=samesite,
encoder=encoder, decoder=decoder)
if aioredis is None:
raise RuntimeError("Please install aioredis")
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pytest-aiohttp==0.3.0
pytest-cov==3.0.0
pytest-mock==3.6.1
pytest-sugar==0.9.4
aiohttp<3.9
aiohttp==3.8
multidict==5.2.0
chardet==4.0.0
yarl==1.7.2
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def read(f):
return open(os.path.join(os.path.dirname(__file__), f)).read().strip()


install_requires = ['aiohttp>=3.0.1', 'typing_extensions>=3.7.4; python_version<"3.8"']
install_requires = ['aiohttp>=3.8', 'typing_extensions>=3.7.4; python_version<"3.8"']
extras_require = {
'aioredis': ['aioredis>=1.0.0'],
'aiomcache': ['aiomcache>=0.5.2'],
Expand Down

0 comments on commit cc4f6f5

Please sign in to comment.