From a8f420ff9d09abcc69f1ce1d03e249b7fc9fdc5d Mon Sep 17 00:00:00 2001 From: suryabulusu Date: Wed, 14 Aug 2024 16:50:44 +0530 Subject: [PATCH 1/2] group in claims --- app/router/auth.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/router/auth.py b/app/router/auth.py index f9466f4..af60c54 100644 --- a/app/router/auth.py +++ b/app/router/auth.py @@ -54,7 +54,11 @@ def create_access_token(auth_user: AuthUser, Authorize: AuthJWT = Depends()): def refresh_token(Authorize: AuthJWT = Depends()): Authorize.jwt_refresh_token_required() current_user = Authorize.get_jwt_subject() - new_access_token = Authorize.create_access_token(subject=current_user) + old_data = Authorize.get_raw_jwt() + custom_claims = {"group": old_data["group"]} + new_access_token = Authorize.create_access_token( + subject=current_user, user_claims=custom_claims + ) return {"access_token": new_access_token} From a15936b672a2f9d8b225e883aaf7e0d7df8defc5 Mon Sep 17 00:00:00 2001 From: suryabulusu Date: Wed, 14 Aug 2024 16:52:48 +0530 Subject: [PATCH 2/2] checks if group in old data --- app/router/auth.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/router/auth.py b/app/router/auth.py index af60c54..91ffb27 100644 --- a/app/router/auth.py +++ b/app/router/auth.py @@ -55,7 +55,10 @@ def refresh_token(Authorize: AuthJWT = Depends()): Authorize.jwt_refresh_token_required() current_user = Authorize.get_jwt_subject() old_data = Authorize.get_raw_jwt() - custom_claims = {"group": old_data["group"]} + if "group" in old_data: + custom_claims = {"group": old_data["group"]} + else: + custom_claims = {} new_access_token = Authorize.create_access_token( subject=current_user, user_claims=custom_claims )