diff --git a/src/python-fastui/fastui/auth/github.py b/src/python-fastui/fastui/auth/github.py index ef5a68c4..d53ba69f 100644 --- a/src/python-fastui/fastui/auth/github.py +++ b/src/python-fastui/fastui/auth/github.py @@ -4,11 +4,10 @@ from typing import TYPE_CHECKING, AsyncIterator, Dict, List, Tuple, Union, cast from urllib.parse import urlencode -import httpx -import jwt from pydantic import BaseModel, SecretStr, TypeAdapter, field_validator if TYPE_CHECKING: + import httpx from fastapi import Request from fastapi.responses import JSONResponse @@ -69,7 +68,7 @@ class GitHubAuthProvider: def __init__( self, - httpx_client: httpx.AsyncClient, + httpx_client: 'httpx.AsyncClient', github_client_id: str, github_client_secret: SecretStr, *, @@ -118,6 +117,8 @@ async def create( """ Async context manager to create a GitHubAuth instance with a new `httpx.AsyncClient`. """ + import httpx + async with httpx.AsyncClient() as client: yield cls( client, @@ -267,10 +268,14 @@ def __init__(self, secret: SecretStr, max_age: timedelta = timedelta(minutes=5)) self._max_age = max_age async def new_state(self) -> str: + import jwt + data = {'created_at': datetime.now().isoformat()} return jwt.encode(data, self._secret.get_secret_value(), algorithm='HS256') async def check_state(self, state: str) -> bool: + import jwt + try: d = jwt.decode(state, self._secret.get_secret_value(), algorithms=['HS256']) except jwt.DecodeError: diff --git a/src/python-fastui/requirements/render.txt b/src/python-fastui/requirements/render.txt index 683fa919..3d1fa143 100644 --- a/src/python-fastui/requirements/render.txt +++ b/src/python-fastui/requirements/render.txt @@ -3,4 +3,4 @@ src/python-fastui uvicorn[standard] httpx -libsql-client +PyJWT diff --git a/src/python-fastui/requirements/test.in b/src/python-fastui/requirements/test.in index ba6ee03c..5928ebed 100644 --- a/src/python-fastui/requirements/test.in +++ b/src/python-fastui/requirements/test.in @@ -4,5 +4,4 @@ pytest-pretty dirty-equals pytest-asyncio httpx -# libsql-client is used by demo -libsql-client +PyJWT