question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error w/ google oauth

See original GitHub issue

Hello, I can’t made a successful auth against google oauth because an error (that seems related or identical to https://github.com/authlib/loginpass/issues/47).

Here is the relevant code:

config = Config(".env")  # pylint: disable=invalid-name
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'
    }
)

async def login(request):
    redirect_uri = request.url_for('auth')
    return await oauth.google.authorize_redirect(request, redirect_uri)

async def auth(request):
    logging.critical(request.headers)
    token = await oauth.google.authorize_access_token(request)
    user = await oauth.google.parse_id_token(request, token)
    request.session['user'] = dict(user)
    return RedirectResponse(url='/')

ROUTES = [
    Route('/login', endpoint=login),
    Route('/auth', endpoint=auth),
]

app = Starlette(debug=True, routes=ROUTES)  # pylint: disable=invalid-name

when /auth endpoint is hit after a successful authentication, I get this traceback (first line is mine):

[osso] CRITICAL: Headers({'host': 'osso.dev.scimmia.net', 'x-request-id': '299db1f2a6d8f187459083ed590d4adb', 'x-real-ip': '10.42.0.1', 'x-forwarded-for': '10.42.0.1', 'x-forwarded-host': 'osso.dev.scimmia.net', 'x-forwarded-port': '443', 'x-forwarded-proto': 'https', 'x-scheme': 'https', 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'accept-language': 'en-US,en;q=0.5', 'accept-encoding': 'gzip, deflate, br', 'referer': 'https://accounts.google.com/', 'dnt': '1', 'upgrade-insecure-requests': '1'})
[osso] INFO:     10.42.0.1:0 - "GET /auth?state=VNyCSjjCXSojWBTqNjsm3XlxBSJEgg&code=4%2FwwEnVamW5jzr4hOz4agsa1kjrKBlCOrMJTdO0pbFM9nq9qDbJ7-riJQ4Sh9TeokDyvz47FnRtY4DQsMMNH3N_II&scope=email+profile+openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile&authuser=0&prompt=consent HTTP/1.1" 500 Internal Server Error
[osso] ERROR:    Exception in ASGI application
[osso] Traceback (most recent call last):
[osso]   File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
[osso]     result = await app(self.scope, self.receive, self.send)
[osso]   File "/usr/local/lib/python3.7/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
[osso]     return await self.app(scope, receive, send)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/applications.py", line 102, in __call__
[osso]     await self.middleware_stack(scope, receive, send)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 181, in __call__
[osso]     raise exc from None
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/middleware/errors.py", line 159, in __call__
[osso]     await self.app(scope, receive, _send)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette_authlib/middleware.py", line 122, in __call__
[osso]     await self.app(scope, receive, send_wrapper)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/exceptions.py", line 82, in __call__
[osso]     raise exc from None
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/exceptions.py", line 71, in __call__
[osso]     await self.app(scope, receive, sender)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 550, in __call__
[osso]     await route.handle(scope, receive, send)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 227, in handle
[osso]     await self.app(scope, receive, send)
[osso]   File "/usr/local/lib/python3.7/site-packages/starlette/routing.py", line 41, in app
[osso]     response = await func(request)
[osso]   File "./osso/app.py", line 79, in auth
[osso]     token = await oauth.google.authorize_access_token(request)
[osso]   File "/usr/local/lib/python3.7/site-packages/authlib/integrations/starlette_client/integration.py", line 58, in authorize_access_token
[osso]     return await self.fetch_access_token(**params)
[osso]   File "/usr/local/lib/python3.7/site-packages/authlib/integrations/base_client/async_app.py", line 105, in fetch_access_token
[osso]     token = await client.fetch_token(token_endpoint, **kwargs)
[osso]   File "/usr/local/lib/python3.7/site-packages/authlib/integrations/httpx_client/oauth2_client.py", line 120, in _fetch_token
[osso]     return self.parse_response_token(resp.json())
[osso]   File "/usr/local/lib/python3.7/site-packages/authlib/oauth2/client.py", line 348, in parse_response_token
[osso]     self.handle_error(error, description)
[osso]   File "/usr/local/lib/python3.7/site-packages/authlib/integrations/httpx_client/oauth2_client.py", line 76, in handle_error
[osso]     raise OAuthError(error_type, error_description)
[osso] authlib.common.errors.AuthlibBaseError: invalid_request: Missing parameter: redirect_uri

Expected behavior

A successful login via google oauth

Environment:

  • OS: python:3.7-slim docker image (alpine)
  • Authlib Version: 0.14.1

Thank you, ciao!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
aogiercommented, Feb 22, 2020

I now found the culprit, that’s was an error my side: session cookies w/ negative max-age that did not survived across auth flow 😦((((( thank you, at least I’d learned a bit against authlib’s internals and that’s not bad at all! I’m sorry for the noise, ciao!

0reactions
lepturecommented, May 23, 2020

@aogier We have a Google example for starlette: https://github.com/authlib/demo-oauth-client/tree/master/starlette-google-login

I didn’t reproduce your problem. The starlette SessionMiddleware works well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authorization Errors | Device Access - Google Developers
When attempting to get an access or refresh token, you will get an "Invalid client" error if you provide an incorrect OAuth 2.0...
Read more >
Google OAuth 2 authorization - Error: redirect_uri_mismatch
Go to the console for your project and look under API Access. You should see your client ID & client secret there, along...
Read more >
OAuth HTTP error response reference | Apigee X | Google Cloud
The error names and HTTP response codes associated with the OAuthV2 policies are described in each policy's reference documentation:.
Read more >
Troubleshoot Sign in with Google - Google Account Help
This guide can help you troubleshoot issues you encounter while you use Sign in with Google to sign in to third-party apps or...
Read more >
HTTP OAuth2 Connection to Gmail and Google API fails after ...
I get this error message from my Gmail/Google API HTTP steps: No ... The addtional params will tell Google to return the access...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found