Skip to content

Commit

Permalink
Merge pull request #450 from MTES-MCT/fix/refresh-token
Browse files Browse the repository at this point in the history
Fix refresh token
  • Loading branch information
tristan-gueguen authored Nov 5, 2024
2 parents 266acc2 + 4e9cbab commit be18158
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
10 changes: 8 additions & 2 deletions app/controllers/authentication.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import graphene
from flask import after_this_request, jsonify
from flask_jwt_extended import jwt_required, get_jwt_identity

from flask_jwt_extended import (
jwt_required,
get_jwt_identity,
current_user as current_actor,
)
from app import app, db
from app.controllers.utils import Void
from app.domain.user import (
Expand Down Expand Up @@ -124,6 +127,9 @@ def mutate(cls, _, info):
@jwt_required(refresh=True)
def rest_refresh_token():
try:
if not current_actor:
raise AuthenticationError("Current user not found")

identity = get_jwt_identity()
if identity and identity.get("controller"):
tokens = refresh_controller_token()
Expand Down
1 change: 0 additions & 1 deletion app/helpers/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ def logout():
db.session.commit()


@jwt_required(refresh=True)
def delete_refresh_token():
from app.models.refresh_token import RefreshToken
from app.models.controller_refresh_token import ControllerRefreshToken
Expand Down
6 changes: 4 additions & 2 deletions app/helpers/authentication_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ def wrap_jwt_errors(f):
def wrapper(*args, **kwargs):
try:
return f(*args, **kwargs)
except (NoAuthorizationError, InvalidHeaderError):
except (NoAuthorizationError, InvalidHeaderError) as e:
app.logger.info(f"Authorization error: {str(e)}")
raise AuthenticationError(
"Unable to find a valid cookie or authorization header"
)
except (JWTExtendedException, PyJWTError):
except (JWTExtendedException, PyJWTError) as e:
app.logger.info(f"JWT error: {str(e)}")
raise AuthenticationError("Invalid token")

return wrapper
Expand Down
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class TestConfig(Config):


class ProdConfig(Config):
ACCESS_TOKEN_EXPIRATION = timedelta(minutes=100)
ACCESS_TOKEN_EXPIRATION = timedelta(minutes=960) # 16h
MINIMUM_ACTIVITY_DURATION = timedelta(minutes=0)


Expand Down

0 comments on commit be18158

Please sign in to comment.