feat(auth): sync Keycloak users for authorization
This commit is contained in:
@@ -52,6 +52,7 @@ async def get_current_metadata_user(
|
||||
):
|
||||
keycloak_sub = _keycloak_sub_from_payload(keycloak_payload)
|
||||
username = get_keycloak_preferred_username(keycloak_payload)
|
||||
email = _email_from_payload(keycloak_payload)
|
||||
try:
|
||||
user = await metadata_repo.get_user_by_keycloak_id(keycloak_sub)
|
||||
except SQLAlchemyError as exc:
|
||||
@@ -65,13 +66,14 @@ async def get_current_metadata_user(
|
||||
) from exc
|
||||
if not user or not user.is_active:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN, detail="Inactive user"
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="User authorization pending",
|
||||
)
|
||||
try:
|
||||
user = await metadata_repo.refresh_user_keycloak_snapshot(
|
||||
user,
|
||||
username=username,
|
||||
email=_email_from_payload(keycloak_payload),
|
||||
email=email,
|
||||
)
|
||||
except SQLAlchemyError as exc:
|
||||
logger.error(
|
||||
|
||||
Reference in New Issue
Block a user