mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Fix jwks validation in scanner
This commit is contained in:
parent
2ce696a07b
commit
6427aafc4d
@ -77,7 +77,7 @@ app = FastAPI(
|
|||||||
)
|
)
|
||||||
async def trigger_scan(
|
async def trigger_scan(
|
||||||
tasks: BackgroundTasks,
|
tasks: BackgroundTasks,
|
||||||
_: Annotated[None, Security(validate_bearer, scopes=["scanner."])],
|
_: Annotated[None, Security(validate_bearer, scopes=["scanner.trigger"])],
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Trigger a full scan of the filesystem, trying to find new videos & deleting old ones.
|
Trigger a full scan of the filesystem, trying to find new videos & deleting old ones.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
from logging import getLogger
|
||||||
from typing import Annotated
|
from typing import Annotated
|
||||||
|
|
||||||
import jwt
|
import jwt
|
||||||
@ -6,6 +7,8 @@ from fastapi import Depends, HTTPException
|
|||||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer, SecurityScopes
|
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer, SecurityScopes
|
||||||
from jwt import PyJWKClient
|
from jwt import PyJWKClient
|
||||||
|
|
||||||
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
jwks_client = PyJWKClient(
|
jwks_client = PyJWKClient(
|
||||||
os.environ.get("JWKS_URL", "http://auth:4568/.well-known/jwks.json")
|
os.environ.get("JWKS_URL", "http://auth:4568/.well-known/jwks.json")
|
||||||
)
|
)
|
||||||
@ -21,6 +24,7 @@ def validate_bearer(
|
|||||||
payload = jwt.decode(
|
payload = jwt.decode(
|
||||||
token.credentials,
|
token.credentials,
|
||||||
jwks_client.get_signing_key_from_jwt(token.credentials).key,
|
jwks_client.get_signing_key_from_jwt(token.credentials).key,
|
||||||
|
algorithms=["RS256"],
|
||||||
issuer=os.environ.get("JWT_ISSUER"),
|
issuer=os.environ.get("JWT_ISSUER"),
|
||||||
)
|
)
|
||||||
for scope in perms.scopes:
|
for scope in perms.scopes:
|
||||||
@ -34,6 +38,7 @@ def validate_bearer(
|
|||||||
)
|
)
|
||||||
return payload
|
return payload
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error("Failed to parse token", exc_info=e)
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=403,
|
status_code=403,
|
||||||
detail="Could not validate credentials",
|
detail="Could not validate credentials",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user