hanchon-live / tutorial-fastapi-oauth

Use Google Login (OAuth) with FastAPI
59 stars 20 forks source link

when start in docker with workers get error after first auth #4

Open Badasper opened 2 years ago

Badasper commented 2 years ago

Hello, very useful tutorial, thank you, When I start project in docker i get error :

Badasper commented 2 years ago

maybe this is the correct behavior

Badasper commented 2 years ago

If I serve app in docker container with gunicorn/uvicorn in some case I got Get FastAPI JWT Token" 403 CSRF Warning! State not equal in request and response. if I delay or push others button before push button get token

hanchon commented 2 years ago

I'll test it this weekend and try to replicate your problem

abhinavkulkarni commented 2 years ago

@hanchon: I am running this on my machine (not in a docker container) and I also get the same error.

I simply set the environmental variables:

GOOGLE_CLIENT_ID=***
GOOGLE_CLIENT_SECRET=***
SECRET_KEY=secret
API_SECRET_KEY=secret

python3 main.py

And I get the same 401 Unauthorized error: 'mismatching_state: CSRF Warning! State not equal in request and response.'

Please note that I am able to get through guide 1 (that is my Google sign in is working), just that JWT token part introduces the above problem.

Thanks for the guide nonetheless!

hanchon commented 2 years ago

Sorry I couldn't look into this problem. I'll try to debug the error, but I don't know If I'm going to have time. Sorry! I'm releasing a new project this week and I have little to no free time

imneonizer commented 2 years ago

I have the same issue, I guess this could be due to mismatching SECRET_KEY. My question is do I need to add middle ware in auth_app and main_app with same SECRET_KEY ? or I can just add the middle ware in main app and it will be passed down to all sub apps ?

I resolved this by replacing sub apps with APIRouter() and using same session middleware.