Browse Source

Try to ensure a fresh token on request

main
decentral1se 5 months ago
parent
commit
777bd824a5
Signed by: decentral1se GPG Key ID: 92DAD76BD9567B8A
  1. 7
      keycloak_collective_portal/dependencies.py
  2. 4
      keycloak_collective_portal/routes/register.py

7
keycloak_collective_portal/dependencies.py

@ -7,6 +7,13 @@ from fastapi import Depends, Request
from humanize import naturaldelta
async def fresh_token(request: Request):
"""Ensure fresh credentials for speaking to Keycloak."""
from keycloak_collective_portal.keycloak import init_keycloak
request.app.state.keycloak = init_keycloak()
async def logged_in(request: Request):
"""Ensure the user is logged in."""
from keycloak_collective_portal.exceptions import RequiresLoginException

4
keycloak_collective_portal/routes/register.py

@ -6,7 +6,7 @@ from datetime import timedelta
from fastapi import APIRouter, Depends, Form, Request
from keycloak_collective_portal.dependencies import get_invites
from keycloak_collective_portal.dependencies import fresh_token, get_invites
router = APIRouter()
@ -50,7 +50,7 @@ async def register_invite(
)
@router.post("/form/keycloak/register")
@router.post("/form/keycloak/register", dependencies=[Depends(fresh_token)])
def form_keycloak_register(
request: Request,
first_name: str = Form(...),

Loading…
Cancel
Save