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

@lepture still getting this error #486

Closed
mr-haseeb opened this issue Sep 7, 2022 · 4 comments
Closed

@lepture still getting this error #486

mr-haseeb opened this issue Sep 7, 2022 · 4 comments

Comments

@mr-haseeb
Copy link

@lepture Hi there! I've tried the 1.0.0 version just now, and it seems the issue persists with Google Oauth2.

oauth = OAuth()
oauth.register(
    name='google',
    server_metadata_url='https://accounts.google.com/.well-known/openid-configuration',
    client_kwargs={
        'scope': 'openid email profile'
    },
    client_id=GOOGLE_OAUTH2_CLIENT_ID,
    client_secret=GOOGLE_OAUTH2_CLIENT_SECRET
)



@app.route('/oauth2-login')
async def oauth2_login(request: Request):
    # absolute url for callback
    # we will define it below
    redirect_uri = request.url_for('oauth2_auth')
    return await oauth.google.authorize_redirect(request, redirect_uri)


@app.route('/oauth2-auth')
async def oauth2_auth(request: Request):
    token = await oauth.google.authorize_access_token(request)
    user = token['userinfo']
    return user

My stacktrace :

Traceback (most recent call last):
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 376, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 75, in __call__
    return await self.app(scope, receive, send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/fastapi/applications.py", line 208, in __call__
    await super().__call__(scope, receive, send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/middleware/cors.py", line 78, in __call__
    await self.app(scope, receive, send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/middleware/sessions.py", line 75, in __call__
    await self.app(scope, receive, send_wrapper)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/asgi_correlation_id/middleware.py", line 60, in __call__
    await self.app(scope, receive, handle_outgoing_request)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/home/sorasful/dev/my_api_async/my_api/__main__.py", line 168, in oauth2_auth
    token = await oauth.google.authorize_access_token(request)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/authlib/integrations/starlette_client/apps.py", line 74, in authorize_access_token
    params = self._format_state_params(state_data, params)
  File "/home/sorasful/.cache/pypoetry/virtualenvs/my-api-5UH-8tMH-py3.10/lib/python3.10/site-packages/authlib/integrations/base_client/sync_app.py", line 234, in _format_state_params
    raise MismatchingStateError()
authlib.integrations.base_client.errors.MismatchingStateError: mismatching_state: CSRF Warning! State not equal in request and response.

Originally posted by @sorasful in #376 (comment)

@mr-haseeb
Copy link
Author

i am getting this error dont know why

@joonas-yoon
Copy link

joonas-yoon commented Sep 8, 2022

would you try to return as JSONResponse like:

@app.route('/oauth2-auth')
async def oauth2_auth(request: Request):
    token = await oauth.google.authorize_access_token(request)
    user = token['userinfo']
    return JSONResponse(status_code=200, content=user)

it works to me

@lepture
Copy link
Owner

lepture commented Sep 9, 2022

@mr-haseeb you don't have configured session correct.

@lepture
Copy link
Owner

lepture commented Sep 12, 2022

Please test with https://github.com/authlib/demo-oauth-client

@lepture lepture closed this as completed Sep 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants