Skip to content

Commit

Permalink
make PyJWT optional, install it
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Feb 9, 2024
1 parent 8811321 commit 6cb953d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/python-fastui/fastui/auth/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
*,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/python-fastui/requirements/render.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
src/python-fastui
uvicorn[standard]
httpx
libsql-client
PyJWT
3 changes: 1 addition & 2 deletions src/python-fastui/requirements/test.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ pytest-pretty
dirty-equals
pytest-asyncio
httpx
# libsql-client is used by demo
libsql-client
PyJWT

0 comments on commit 6cb953d

Please sign in to comment.