Django redirects to previous page after external login to OAuth

I use Twitter OAuth to login. Logging in allows users to connect to Twitter and, if successful, OAuth returns them to the specified URL. From this URL, I would like to redirect users to the page they were on before logging in.

What is a good way to do this?

+4
source share
2 answers

Two ways:

  • Build your OAuth URL so that it sends them back to the desired page or at least says next=url in querystring. This is the most reliable, but it can break (and it looks ugly, but who is copying and pasting OAuth URLs?)

  • Save the session containing the last requested "real" page. I say "real" because I do not think the authorization / registration pages are real. So, every hit, check which URL it is included, if it is not connected to the server, save it in the session. When they get to the OAuth-auccess page, redirect them to the session value. This can be done in the context of a processor or middleware. Cookies and logout are required to be destroyed.

+3
source

I use twitter redirect url in auth url and its work for me.

0
source

Source: https://habr.com/ru/post/1314366/


All Articles