hanchon-live / tutorial-fastapi-oauth

Use Google Login (OAuth) with FastAPI
60 stars 21 forks source link

Getting error while redirecting to auth/token #14

Open jaswanthm1855 opened 1 year ago

jaswanthm1855 commented 1 year ago

Getting error while redirecting to auth/token

error: mismatching_state: CSRF Warning! State not equal in request and response.

levietanh0001 commented 1 year ago

Getting error while redirecting to auth/token

error: mismatching_state: CSRF Warning! State not equal in request and response.

I had the same issue and this suggestion helped me: https://stackoverflow.com/a/73640142/11422689

Change from http to https with mkcert and register the domains in google developer console as follows: image

Down below is my /auth endpoint with the latest Authlib==1.1.0

@app.route('/auth')
async def auth(request: Request):
    token = await oauth.google.authorize_access_token(request)
    user = token.get('userinfo')
    if user:
        request.session['user'] = user
    return RedirectResponse(url='/')