Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace requests with httpx #113

Merged
merged 1 commit into from
May 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions helpdesk/libs/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

import requests
import httpx
from starlette.authentication import (
AuthenticationBackend,
AuthCredentials,
Expand Down Expand Up @@ -36,13 +36,13 @@ def fetch_jwk(self):

def get(self, *args, **kwargs):
if self.client_kwargs:
r = requests.get(*args, **kwargs, **self.client_kwargs)
r = httpx.get(*args, **kwargs, **self.client_kwargs)
else:
r = requests.get(*args, **kwargs)
r = httpx.get(*args, **kwargs)
r.raise_for_status()
return r.json()

def valide_token(self, token: str):
def validate_token(self, token: str):
"""validate token string, return a parsed token if valid, return None if not valid
:return tuple (is_token -> bool, id_token or None)
The BearerAuthMiddleware would use this to decide if we should validate the token in the next provider.
Expand Down Expand Up @@ -97,7 +97,7 @@ async def authenticate(self, request):
return AuthCredentials([]), UnauthenticatedUser()

try:
user = User.from_json(userinfo)
user = User.parse_raw(userinfo)
return user.auth_credentials, user
except Exception:
return AuthCredentials([]), UnauthenticatedUser()
Expand All @@ -111,7 +111,7 @@ async def dispatch(self, request, call_next):
if token_str:
for validator_name, validator in registed_validator.items():
logger.info("Trying to validate token with %s", validator_name)
is_token, id_token = validator.valide_token(token_str)
is_token, id_token = validator.validate_token(token_str)
if not is_token:
break
if is_token and not id_token:
Expand Down