fix: fixes auth check for auto_login (#8796)
This commit is contained in:
parent
69ceaea739
commit
fe58d69ae7
1 changed files with 4 additions and 4 deletions
|
|
@ -59,6 +59,7 @@ async def api_key_security(
|
||||||
if settings_service.auth_settings.skip_auth_auto_login:
|
if settings_service.auth_settings.skip_auth_auto_login:
|
||||||
result = await get_user_by_username(db, settings_service.auth_settings.SUPERUSER)
|
result = await get_user_by_username(db, settings_service.auth_settings.SUPERUSER)
|
||||||
logger.warning(AUTO_LOGIN_WARNING)
|
logger.warning(AUTO_LOGIN_WARNING)
|
||||||
|
return UserRead.model_validate(result, from_attributes=True)
|
||||||
else:
|
else:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
|
@ -72,19 +73,18 @@ async def api_key_security(
|
||||||
detail="An API key must be passed as query or header",
|
detail="An API key must be passed as query or header",
|
||||||
)
|
)
|
||||||
|
|
||||||
elif query_param:
|
|
||||||
result = await check_key(db, query_param)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
result = await check_key(db, header_param)
|
result = await check_key(db, query_param or header_param)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
detail="Invalid or missing API key",
|
detail="Invalid or missing API key",
|
||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(result, User):
|
if isinstance(result, User):
|
||||||
return UserRead.model_validate(result, from_attributes=True)
|
return UserRead.model_validate(result, from_attributes=True)
|
||||||
|
|
||||||
msg = "Invalid result type"
|
msg = "Invalid result type"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue