From 290a99d043fbce9840aa75b75fc3165613095ca9 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 25 Apr 2021 15:46:53 +0100 Subject: [PATCH 1/3] Add samesite support. --- aiohttp_session/__init__.py | 8 ++++++-- aiohttp_session/cookie_storage.py | 3 ++- aiohttp_session/memcached_storage.py | 3 ++- aiohttp_session/nacl_storage.py | 3 ++- aiohttp_session/redis_storage.py | 3 ++- setup.py | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/aiohttp_session/__init__.py b/aiohttp_session/__init__.py index 9a88a317..ed6fb7b5 100644 --- a/aiohttp_session/__init__.py +++ b/aiohttp_session/__init__.py @@ -23,6 +23,7 @@ class _CookieParams(TypedDict, total=False): path: str secure: Optional[bool] httponly: bool + samesite: Optional[str] expires: str @@ -216,6 +217,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: @@ -225,7 +227,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 @@ -302,12 +305,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: diff --git a/aiohttp_session/cookie_storage.py b/aiohttp_session/cookie_storage.py index b28b8a14..1adcb6d2 100644 --- a/aiohttp_session/cookie_storage.py +++ b/aiohttp_session/cookie_storage.py @@ -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): diff --git a/aiohttp_session/memcached_storage.py b/aiohttp_session/memcached_storage.py index d3b561b2..df043c7e 100644 --- a/aiohttp_session/memcached_storage.py +++ b/aiohttp_session/memcached_storage.py @@ -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 diff --git a/aiohttp_session/nacl_storage.py b/aiohttp_session/nacl_storage.py index a2cae35b..352b34c4 100644 --- a/aiohttp_session/nacl_storage.py +++ b/aiohttp_session/nacl_storage.py @@ -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) diff --git a/aiohttp_session/redis_storage.py b/aiohttp_session/redis_storage.py index 8a595517..d9a7fd18 100644 --- a/aiohttp_session/redis_storage.py +++ b/aiohttp_session/redis_storage.py @@ -26,13 +26,14 @@ def __init__( # type: ignore[no-any-unimported] # TODO: aioredis 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") diff --git a/setup.py b/setup.py index 3a90a64e..e92b0d0f 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,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'], From 6467041f10abd08b1f5c1f64bae3fa368476236c Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 31 Oct 2021 22:10:59 +0000 Subject: [PATCH 2/3] Update requirements-dev.txt --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index dc69d816..8b814304 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -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.7 +aiohttp==3.8 multidict==4.7.6 chardet==3.0.4 yarl==1.7.0 From 594a06b7eb7ac7e919f6d73c9c5b058c08044814 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Sun, 31 Oct 2021 22:13:30 +0000 Subject: [PATCH 3/3] Update setup.py --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 3dbaee3e..54322684 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ def read(f): return open(os.path.join(os.path.dirname(__file__), f)).read().strip() + install_requires = ['aiohttp>=3.8', 'typing_extensions>=3.7.4; python_version<"3.8"'] extras_require = { 'aioredis': ['aioredis>=1.0.0'],