Simplify oauth_authorized with redirect
See original GitHub issuerepost from https://github.com/singingwolfboy/flask-dance/issues/203#issuecomment-486333141 (CC @daenney @singingwolfboy)
Right now the expectation is that writers of oauth_authorized
callbacks handle saving the token if they want a redirect. This leads to more complicated logic to handle redirects (see linked comment), reposted here:
why push that responsibility on the user? Seems like there is a non trivial amount of logic in setting the token (ie handling errors) that I would guess most consumers would still want to use.
I think in the base case of just wanting to customize redirects (ie to send the user back to the where they originally came from) where the logic is:
next_url = flask.session["next_url"]
return flask.redirect(next_url)
having to also set the token seems unnatural.
I suggest improving the DX here to allow returning the a response and still re-using the existing set token logic.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (10 by maintainers)
Top GitHub Comments
Doing it in your view code is one way. You could also hook into the
oauth_before_login
signal:Yup, that ought to do the trick. One additional tip, when doing the redirect it’s probably good to do:
Alternatively, you can set the default argument to
.pop("next_url", "app.index")
to avoid theif next_url
check and always redirect.By using
.pop
you remove the value from the session. There’s no need to keep it around anymore and avoids it still being accidentally set and causing surprises if/when a user re-authenticates.