joonas-yoon / fastapi-react-oauth2

FastAPI + MongoDB with Beanie + React Login Example
26 stars 3 forks source link

What is correct GOOGLE_CALLBACK_URL ? #1

Open philipshurpik opened 8 months ago

philipshurpik commented 8 months ago

Hi!
Thanks for great project! If I'm running it with default parameters (Configs.GOOGLE_CALLBACK_URL is None) and after auth it redirects me to this url:

http://localhost:8000/auth/google/callback?state=XXX&code=YYY&scope=ZZZ&prompt=consent

With content on page: {"access_token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiNjVlNWYyOGY1MDQxMTc5NzUxMDQ0ODE2IiwiYXVkIjpbImZhc3RhcGktdXNlcnM6YXV0aCJdLCJleHAiOjE3MDk1ODc3MjZ9.HZf6ar6vSvfXh_q8EjD-A-Ds99H6P_4CGWwZ6YxT6Z8","token_type":"bearer"}

I understand that everything should work slightly different and redirect to actual user page... But how to change config or code to achieve that?

joonas-yoon commented 8 months ago

Hi, glad to comment with you and thanks.

If I guess correctly, you would want to set a parameter for google to redirect (Configs.GOOGLE_CALLBACK_URL).

you can create your own environment file for parameter settings such as dev.env. please refer fastapi/app/configs.py and fastapi/sample.env both. I hope that will be helpful.

and more, you can command to run to change environment file to read as following on your terminal:

# you should have xyz.env file
$ ENV=xyz uvicorn main:app --reload
# then now app get configs from xyz.env file
joonas-yoon commented 8 months ago

and you can add variable with one line (like GOOGLE_CALLBACK_URL=...) on your env file to use