|
8 | 8 | from dateutil import tz
|
9 | 9 | from envs import env
|
10 | 10 | from faunadb.errors import BadRequest, NotFound
|
| 11 | +from jwt import ExpiredSignatureError |
11 | 12 | from valley.exceptions import ValidationException
|
12 | 13 | from valley.utils import import_util
|
13 | 14 | from werkzeug.utils import cached_property
|
|
17 | 18 | from pfunk.contrib.auth.resources import LoginUser, UpdatePassword, Public, UserRole, LogoutUser
|
18 | 19 | from pfunk.contrib.auth.views import ForgotPasswordChangeView, LoginView, SignUpView, VerifyEmailView, LogoutView, UpdatePasswordView, ForgotPasswordView
|
19 | 20 | from pfunk.contrib.email.base import send_email
|
20 |
| -from pfunk.exceptions import LoginFailed, DocNotFound |
| 21 | +from pfunk.exceptions import LoginFailed, DocNotFound, Unauthorized |
21 | 22 | from pfunk.fields import EmailField, SlugField, ManyToManyField, ListField, ReferenceField, StringField, EnumField
|
22 | 23 |
|
23 | 24 | AccountStatus = Enum(name='AccountStatus', choices=['ACTIVE', 'INACTIVE'])
|
@@ -79,8 +80,11 @@ def decrypt_jwt(cls, encoded):
|
79 | 80 | headers = jwt.get_unverified_header(encoded)
|
80 | 81 | keys = cls.import_keys()
|
81 | 82 | 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, |
83 | 85 | options={"require": ["iat", "exp", "nbf", 'iss', 'til']})
|
| 86 | + except ExpiredSignatureError: |
| 87 | + raise Unauthorized('Unauthorized') |
84 | 88 | pay_f = Fernet(key.get('payload_key').encode())
|
85 | 89 | k = pay_f.decrypt(decoded.get('til').encode())
|
86 | 90 | return json.loads(k.decode())
|
@@ -341,8 +345,8 @@ class UserGroups(Collection):
|
341 | 345 | List of permissions, `['create', 'read', 'delete', 'write']`
|
342 | 346 | """
|
343 | 347 | 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')) |
346 | 350 | permissions = ListField()
|
347 | 351 |
|
348 | 352 | def __unicode__(self):
|
|
0 commit comments