update session
This commit is contained in:
@@ -3,7 +3,6 @@ from typing import Annotated
|
||||
from uuid import uuid4
|
||||
|
||||
import boto3
|
||||
import jwt
|
||||
from aws_lambda_powertools.event_handler import (
|
||||
Response,
|
||||
)
|
||||
@@ -17,10 +16,8 @@ from passlib.hash import pbkdf2_sha256
|
||||
|
||||
from boto3clients import dynamodb_client
|
||||
from config import (
|
||||
ISSUER,
|
||||
OAUTH2_TABLE,
|
||||
SESSION_EXPIRES_IN,
|
||||
SESSION_SECRET,
|
||||
)
|
||||
|
||||
router = Router()
|
||||
@@ -45,7 +42,7 @@ def session(
|
||||
status_code=HTTPStatus.OK,
|
||||
cookies=[
|
||||
Cookie(
|
||||
name='session_id',
|
||||
name='__session',
|
||||
value=new_session(user_id),
|
||||
http_only=True,
|
||||
secure=True,
|
||||
@@ -127,26 +124,15 @@ def _get_idp_user(
|
||||
|
||||
|
||||
def new_session(sub: str) -> str:
|
||||
session_id = str(uuid4())
|
||||
sid = str(uuid4())
|
||||
now_ = now()
|
||||
exp = ttl(start_dt=now_, seconds=SESSION_EXPIRES_IN)
|
||||
token = jwt.encode(
|
||||
{
|
||||
'sid': session_id,
|
||||
'sub': sub,
|
||||
'iss': ISSUER,
|
||||
'iat': int(now_.timestamp()),
|
||||
'exp': exp,
|
||||
},
|
||||
SESSION_SECRET,
|
||||
algorithm='HS256',
|
||||
)
|
||||
|
||||
with dyn.transact_writer() as transact:
|
||||
transact.put(
|
||||
item={
|
||||
'id': 'SESSION',
|
||||
'sk': session_id,
|
||||
'sk': sid,
|
||||
'user_id': sub,
|
||||
'ttl': exp,
|
||||
'created_at': now_,
|
||||
@@ -155,13 +141,13 @@ def new_session(sub: str) -> str:
|
||||
transact.put(
|
||||
item={
|
||||
'id': sub,
|
||||
'sk': f'SESSION#{session_id}',
|
||||
'sk': f'SESSION#{sid}',
|
||||
'ttl': exp,
|
||||
'created_at': now_,
|
||||
}
|
||||
)
|
||||
|
||||
return token
|
||||
return f'{sid}:{sub}'
|
||||
|
||||
|
||||
class UserNotFoundError(NotFoundError):
|
||||
|
||||
Reference in New Issue
Block a user