aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-09-04 18:31:26 -0500
committerFrederick Muriuki Muriithi2024-09-04 18:31:26 -0500
commit5ce4394c34048c6bbf253124df7b3bed22094d92 (patch)
tree2c23011d7397bd611408d27d5ec0b4f690941caa
parentd8113cb9d6a7addd581266b872be2bacb3509033 (diff)
downloadgn-uploader-5ce4394c34048c6bbf253124df7b3bed22094d92.tar.gz
Add function to update the JSON Web Keys in the session
When new JSON Web Keys (JWKs) are fetched from the server, the function added in this commit will help with updating them in the session for subsequent uses, validating the tokens when needed.
-rw-r--r--uploader/session.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/uploader/session.py b/uploader/session.py
index 8b72bce..019d959 100644
--- a/uploader/session.py
+++ b/uploader/session.py
@@ -1,7 +1,9 @@
"""Deal with user sessions"""
from uuid import UUID, uuid4
+from datetime import datetime
from typing import Any, Optional, TypedDict
+from authlib.jose import KeySet
from flask import request, session
from pymonad.either import Left, Right, Either
@@ -89,3 +91,15 @@ def user_details() -> UserDetails:
def user_token() -> Either:
"""Retrieve the user token."""
return session_info()["user"]["token"]
+
+
+def set_auth_server_jwks(keyset: KeySet) -> KeySet:
+ """Update the JSON Web Keys in the session."""
+ save_session_info({
+ **session_info(),
+ "auth_server_jwks": {
+ "last-updated": datetime.now().timestamp(),
+ "jwks": keyset.as_dict()
+ }
+ })
+ return keyset