MushroomMaula / fastapi_login

FastAPI-Login tries to provide similar functionality as Flask-Login does.
https://pypi.org/project/fastapi-login
MIT License
639 stars 58 forks source link

Redirects after login #15

Closed DevilWarrior closed 4 years ago

DevilWarrior commented 4 years ago

Hi, I currently have things setup where I use cookies with fastapi_login.

manager = LoginManager(SECRET, tokenUrl='/auth/token', use_cookie=True)
manager.cookie_name = 'oversight_token'

On the auth route I build a response object with a RedirectResponse and set the cookie there.

access_token = manager.create_access_token(
    data=dict(sub=email)
)

response = RedirectResponse(url='/bids')
response.set_cookie(
    key=manager.cookie_name,
    value=f"Bearer {access_token}",
    httponly=True,
    max_age=2147483647,
    expires=2147483647,
)
return response

This works only if the redirect has a POST method, does not work for GET routes. Is that the expected behavior? I'm new to fastapi, sorry for the noob question.

MushroomMaula commented 4 years ago

So you are saying you can only set the cookie if '/bids' has a POST method? That seems quite weird

MushroomMaula commented 4 years ago

After searching found this issue on the FastAPI repo which should solve your problem

DevilWarrior commented 4 years ago

Thank you!!!!