Skip to content

Commit

Permalink
Merge branch 'master' into SKIL-518
Browse files Browse the repository at this point in the history
  • Loading branch information
aparriaran committed Nov 20, 2024
2 parents c878113 + eadc20e commit b36a96e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion BackEndFlask/controller/security/CustomDecorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def verify_token(refresh: bool):
if not id: raise InvalidQueryParamError("Missing user_id")
token = request.headers.get('Authorization').split()[1]
try:
decoded_id = decode_token(token)['sub'] if refresh else decode_token(token)['sub'][0]
decoded_id = int(decode_token(token)['sub'])
except:
raise NoAuthorizationError("No Authorization")
id = to_int(id, "user_id")
Expand Down
8 changes: 4 additions & 4 deletions BackEndFlask/controller/security/utility.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import traceback
from flask import request
from core import app
from jwt import ExpiredSignatureError
Expand All @@ -18,10 +19,10 @@
# jwt expires in 15mins; refresh token expires in 30days
def create_tokens(user_i_d: any) -> 'tuple[str, str]':
with app.app_context():
jwt = create_access_token([user_i_d])
jwt = create_access_token(str(user_i_d))
refresh = request.args.get('refresh_token')
if not refresh:
refresh = create_refresh_token(user_i_d)
refresh = create_refresh_token(str(user_i_d))
return jwt, refresh

# Takes away jwt and refresh tokens from response
Expand Down Expand Up @@ -52,8 +53,7 @@ def token_expired(thing: str) -> bool:
# Function returns the user_id from the sub of the jwt
def token_user_id(thing: str, refresh: bool = False) -> int:
with app.app_context():
if refresh: return decode_token(thing)['sub']
return decode_token(thing)['sub'][0]
return int(decode_token(thing)['sub'])

# Handles conversion issues and warns front end of problems
def to_int(thing: str , subject: str) -> int:
Expand Down

0 comments on commit b36a96e

Please sign in to comment.