From 64b5a67d6209c1227c3040553f2a9b9e3bde394a Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 7 May 2024 04:56:53 +0300 Subject: Save refresh token when it is generated. --- gn_auth/auth/authentication/oauth2/server.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'gn_auth/auth') diff --git a/gn_auth/auth/authentication/oauth2/server.py b/gn_auth/auth/authentication/oauth2/server.py index 5ed7785..70a0e51 100644 --- a/gn_auth/auth/authentication/oauth2/server.py +++ b/gn_auth/auth/authentication/oauth2/server.py @@ -13,6 +13,7 @@ from gn_auth.auth.db import sqlite3 as db from .models.oauth2client import client from .models.oauth2token import OAuth2Token, save_token +from .models.jwtrefreshtoken import JWTRefreshToken, save_refresh_token from .grants.password_grant import PasswordGrant from .grants.authorisation_code_grant import AuthorisationCodeGrant @@ -54,12 +55,17 @@ def create_save_token_func(token_model: type, jwtkey: jwk) -> Callable: }) with db.connection(current_app.config["AUTH_DB"]) as conn: save_token(conn, _token) + save_refresh_token( + conn, + JWTRefreshToken( + token=_token.refresh_token, + client=request.client, user=request.user, - **{ - "refresh_token": None, "revoked": False, - "issued_at": datetime.datetime.now(), - **token - })) + issued_with=uuid.UUID(_jwt["jti"]), + issued_at=datetime.datetime.fromtimestamp(_jwt["iat"]), + expires=datetime.datetime.fromtimestamp(_jwt["iat"]), + revoked=False, + parent_of=None)) return __save_token__ -- cgit v1.2.3