На самом деле я работаю на платформе, использующей инфраструктуру starlette с authlib для аутентификации Google OAuth.
С сегодняшнего дня я получаю 500 Internal Server Error
при вызове oauth.google.authorize_redirect(request, redirect_uri)
с ошибкой httpx.exceptions.ConnectTimeout
.
Я полностью заблудился об этом новом поведении. Я могу воспроизвести его, используя demo-oauth-client
репозиторий, предоставленный authlib
: https://github.com/authlib/demo-oauth-client/tree/master/starlette-google-login
app.py, являющийся:
<code>import json
from starlette.config import Config
from starlette.applications import Starlette
from starlette.middleware.sessions import SessionMiddleware
from starlette.responses import HTMLResponse, RedirectResponse
from authlib.integrations.starlette_client import OAuth
app = Starlette(debug=True)
app.add_middleware(SessionMiddleware, secret_key="!secret")
config = Config('.env')
oauth = OAuth(config)
CONF_URL = 'https://accounts.google.com/.well-known/openid-configuration'
oauth.register(
name='google',
server_metadata_url=CONF_URL,
client_kwargs={
'scope': 'openid email profile'
}
)
@app.route('/')
async def homepage(request):
user = request.session.get('user')
if user:
data = json.dumps(user)
html = (
f'<pre>{data}
''
logout ') return HTMLResponse (html) вернуть HTMLResponse ('
login ') @ app.route ('/ login') async def login (запрос): redirect_uri = request.url_for ('auth') вернуть await oauth.google.authorize_redirect (request, redirect_uri) @ app.route ('/ auth') async def auth (запрос): token = await oauth.google.authorize_access_token (запрос) user = await oauth.google.parse_id_token (запрос, токен) request.session ['user '] = dict (user) return RedirectResponse (url =' / ') @ app.route (' / logout ') async def logout (запрос): request.session.pop (' user ', None) вернуть RedirectResponse (url= '/') if __name__ == '__main__': import uvicorn uvicorn.run (приложение, хост = '127.0.0.1', порт = 8000)
И .env
файл:
GOOGLE_CLIENT_ID=[REDACTED]
GOOGLE_CLIENT_SECRET=[REDCATED]
Есть идеи по поводу этого нового поведения? Я полностью потерян с этим. Спасибо !!