aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/authentication/oauth2
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-05-07 04:56:53 +0300
committerFrederick Muriuki Muriithi2024-05-13 06:16:33 +0300
commit64b5a67d6209c1227c3040553f2a9b9e3bde394a (patch)
treea4e57d0f17f1f6963b40869cc0370e8998486efc /gn_auth/auth/authentication/oauth2
parent04b1d251bc5653df7ea6a454e5fd927d45ce40e4 (diff)
downloadgn-auth-64b5a67d6209c1227c3040553f2a9b9e3bde394a.tar.gz
Save refresh token when it is generated.
Diffstat (limited to 'gn_auth/auth/authentication/oauth2')
-rw-r--r--gn_auth/auth/authentication/oauth2/server.py16
1 files changed, 11 insertions, 5 deletions
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__