api: fix error when connection to websocket via secret_key

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-10-27 15:21:52 +02:00
parent 61d3df5f02
commit f2f12ef0ba

View file

@ -45,7 +45,8 @@ def bearer_auth(raw_header: bytes) -> Optional[User]:
if not user:
raise AuthenticationFailed("Token invalid/expired")
return user
LOCAL.authentik[KEY_AUTH_VIA] = "api_token"
if hasattr(LOCAL, "authentik"):
LOCAL.authentik[KEY_AUTH_VIA] = "api_token"
return tokens.first().user
@ -59,7 +60,8 @@ def token_secret_key(value: str) -> Optional[User]:
outposts = Outpost.objects.filter(managed=MANAGED_OUTPOST)
if not outposts:
return None
LOCAL.authentik[KEY_AUTH_VIA] = "secret_key"
if hasattr(LOCAL, "authentik"):
LOCAL.authentik[KEY_AUTH_VIA] = "secret_key"
outpost = outposts.first()
return outpost.user