File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ def wrapper(*args, **kwargs):
8787 if header == "authorization" :
8888 # Get Auth Value then decode and parse for owner
8989 try :
90- owner = authorization_decoder (request .headers .get (header ))
90+ owner = authorization_decoder (self . app . config , request .headers .get (header ))
9191 except UnSupportedAuthType :
9292 # Continue if catch unsupported type in the event of
9393 # Other headers needing to be checked
@@ -96,6 +96,9 @@ def wrapper(*args, **kwargs):
9696 "decoding is unsupported by flask-casbin at this time"
9797 )
9898 continue
99+ except Exception as e :
100+ self .app .logger .info (e )
101+ continue
99102
100103 if self .user_name_headers and header in map (str .lower , self .user_name_headers ):
101104 owner_audit = owner
Original file line number Diff line number Diff line change 11from base64 import b64decode
22
3+ import jwt
4+
35
46class UnSupportedAuthType (Exception ):
57 status_code = 501
@@ -20,11 +22,12 @@ def to_dict(self):
2022 return rv
2123
2224
23- def authorization_decoder (auth_str : str ):
25+ def authorization_decoder (config , auth_str : str ):
2426 """
2527 Authorization token decoder based on type. This will decode the token and
2628 only return the owner
2729 Args:
30+ config: app.config
2831 auth_str: Authorization string should be in "<type> <token>" format
2932 Returns:
3033 decoded owner from token
@@ -35,6 +38,8 @@ def authorization_decoder(auth_str: str):
3538 """Basic format <user>:<password> return only the user"""
3639 return b64decode (token ).decode ().split (":" )[0 ]
3740 elif type == "Bearer" :
38- raise UnSupportedAuthType ("Bearer is not implemented yet" )
41+ decoded_jwt = jwt .decode (token , config .get ("JWT_SECRET_KEY" ),
42+ algorithms = config .get ('JWT_HASH' ))
43+ return decoded_jwt .get ("identity" , '' )
3944 else :
4045 raise UnSupportedAuthType ("%s Authorization is not supported" % type )
Original file line number Diff line number Diff line change @@ -4,5 +4,6 @@ flask>=0.12.2,~=1.1.2
44itsdangerous == 1.1.0
55jinja2 == 2.11.2
66markupsafe == 1.1.1
7+ pyjwt == 2.0.1
78simpleeval == 0.9.10
89werkzeug == 1.0.1
You can’t perform that action at this time.
0 commit comments