Skip to content

Commit

Permalink
no async in custom auth handler
Browse files Browse the repository at this point in the history
  • Loading branch information
pieroit committed Feb 11, 2025
1 parent 4633745 commit 3572584
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions mkdocs/production/auth/custom-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@ from cat.factory.custom_auth_handler import BaseAuthHandler
from cat.auth.permissions import (
AuthPermission, AuthResource, AuthUserInfo, get_base_permissions
)
import httpx
import requests

class CustomAuthHandler(BaseAuthHandler):

def __init__(self, **config):
self.server_url = config.get("server_url")


async def authorize_user_from_jwt(self, token: str, auth_resource: str, auth_permission: str):
def authorize_user_from_jwt(self, token: str, auth_resource: str, auth_permission: str):
jwt_validation_url = f"{self.server_url}/validate-token"

async with httpx.AsyncClient() as client:
response = await client.get(jwt_validation_url, headers={
"Authorization": f"Bearer {token}"
})
response = requests.get(jwt_validation_url, headers={
"Authorization": f"Bearer {token}"
})

if response.status_code == 200:
user_data = response.json()
Expand All @@ -53,7 +52,7 @@ class CustomAuthHandler(BaseAuthHandler):
return None # If the server responds with an error or doesn't respond at all


async def authorize_user_from_key(self, protocol: str, user_id: str, api_key: str, auth_resource, auth_permission):
def authorize_user_from_key(self, protocol: str, user_id: str, api_key: str, auth_resource, auth_permission):
# Optional: Handle API key authentication, if applicable
return None

Expand Down

0 comments on commit 3572584

Please sign in to comment.