Skip to content

Commit 68f23f5

Browse files
committed
Merge branch 'feature/api'
2 parents ae52907 + 3866423 commit 68f23f5

File tree

4 files changed

+11
-46
lines changed

4 files changed

+11
-46
lines changed

pfunk/contrib/auth/collections.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from dateutil import tz
99
from envs import env
1010
from faunadb.errors import BadRequest, NotFound
11+
from jwt import ExpiredSignatureError
1112
from valley.exceptions import ValidationException
1213
from valley.utils import import_util
1314
from werkzeug.utils import cached_property
@@ -17,7 +18,7 @@
1718
from pfunk.contrib.auth.resources import LoginUser, UpdatePassword, Public, UserRole, LogoutUser
1819
from pfunk.contrib.auth.views import ForgotPasswordChangeView, LoginView, SignUpView, VerifyEmailView, LogoutView, UpdatePasswordView, ForgotPasswordView
1920
from pfunk.contrib.email.base import send_email
20-
from pfunk.exceptions import LoginFailed, DocNotFound
21+
from pfunk.exceptions import LoginFailed, DocNotFound, Unauthorized
2122
from pfunk.fields import EmailField, SlugField, ManyToManyField, ListField, ReferenceField, StringField, EnumField
2223

2324
AccountStatus = Enum(name='AccountStatus', choices=['ACTIVE', 'INACTIVE'])
@@ -79,8 +80,11 @@ def decrypt_jwt(cls, encoded):
7980
headers = jwt.get_unverified_header(encoded)
8081
keys = cls.import_keys()
8182
key = keys.get(headers.get('kid'))
82-
decoded = jwt.decode(encoded, key.get('signature_key'), algorithms="HS256", verify=True,
83+
try:
84+
decoded = jwt.decode(encoded, key.get('signature_key'), algorithms="HS256", verify=True,
8385
options={"require": ["iat", "exp", "nbf", 'iss', 'til']})
86+
except ExpiredSignatureError:
87+
raise Unauthorized('Unauthorized')
8488
pay_f = Fernet(key.get('payload_key').encode())
8589
k = pay_f.decrypt(decoded.get('til').encode())
8690
return json.loads(k.decode())
@@ -341,8 +345,8 @@ class UserGroups(Collection):
341345
List of permissions, `['create', 'read', 'delete', 'write']`
342346
"""
343347
collection_name = 'users_groups'
344-
userID = ReferenceField('pfunk.contrib.auth.collections.User')
345-
groupID = ReferenceField(Group)
348+
userID = ReferenceField(env('USER_COLLECTION', 'pfunk.contrib.auth.collections.User'))
349+
groupID = ReferenceField(env('GROUP_COLLECTION', 'pfunk.contrib.auth.collections.Group'))
346350
permissions = ListField()
347351

348352
def __unicode__(self):

pfunk/web/middleware.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

pfunk/web/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def __init__(self, event, kwargs=None):
5151
super(BaseAPIGatewayRequest, self).__init__(event, kwargs)
5252
self.is_base64_encoded = event.get('isBase64Encoded')
5353
self.body = event.get('body')
54-
self.headers = event.get('headers', {})
55-
self.query_params = event.get('queryStringParameters')
54+
self.headers = event.get('headers') or dict()
55+
self.query_params = event.get('queryStringParameters') or dict()
5656

5757

5858
class WSGIRequest(Request):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pfunk"
3-
version = "0.5.5"
3+
version = "0.5.8"
44
description = "A Python library created make building FaunaDB GraphQL schemas and authentication code easier."
55
authors = ["Brian Jinwright"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)