Commit 1527ef3e authored by Arnaud Vergnet's avatar Arnaud Vergnet
Browse files

fix: add typing to pyramid_jwt

parent 0ca194061137
Pipeline #135830 canceled with stages
in 1 minute and 24 seconds
......@@ -36,6 +36,7 @@
from pyramid.authentication import CallbackAuthenticationPolicy
from pyramid.interfaces import IAuthenticationPolicy, IRendererFactory
from pyramid.request import Request
from pyramid.response import Response
log = logging.getLogger(__name__)
marker = []
......@@ -268,7 +269,7 @@
def _get_cookies(self, request, value, max_age=None, domains=None):
def _get_cookies(self, request: Request, value, max_age=None, domains=None):
profile = self.cookie_profile(request)
if domains is None:
domains = [request.domain]
......@@ -280,7 +281,7 @@
headers = profile.get_headers(value, **kw)
return headers
def remember(self, request, principal, **kw):
def remember(self, request: Request, principal, **kw):
token = self.create_token(principal, self.expiration, self.audience, **kw)
if hasattr(request, "_jwt_cookie_reissued"):
......@@ -290,7 +291,7 @@
return self._get_cookies(request, token, self.max_age, domains=domains)
def forget(self, request):
def forget(self, request: Request):
request._jwt_cookie_reissue_revoked = True
return self._get_cookies(request, None)
......@@ -294,7 +295,7 @@
request._jwt_cookie_reissue_revoked = True
return self._get_cookies(request, None)
def get_claims(self, request):
def get_claims(self, request: Request):
profile = self.cookie_profile.bind(request)
cookie = profile.get_value()
......@@ -309,7 +310,7 @@
self._handle_reissue(request, claims)
return claims
def _handle_reissue(self, request, claims):
def _handle_reissue(self, request: Request, claims: dict):
if not request or not claims:
raise ValueError("Cannot handle JWT reissue: insufficient arguments")
......@@ -331,6 +332,6 @@
headers = self.remember(request, principal, **extra_claims)
def reissue_jwt_cookie(request, response):
if not hasattr(request, "_jwt_cookie_reissue_revoked"):
def reissue_jwt_cookie(inner_request: Request, inner_response: Response):
if not hasattr(inner_request, "_jwt_cookie_reissue_revoked"):
for k, v in headers:
......@@ -336,5 +337,5 @@
for k, v in headers:
response.headerlist.append((k, v))
inner_response.headerlist.append((k, v))
request._jwt_cookie_reissued = True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment