tags:

views:

27

answers:

1

I am using Twitter OAuth to login users. The login takes users to Twitter and upon successful OAuth returns them to a specified url. From this url I would like to redirect users back to the page they were on before logging in.

What is a good way to do this?

A: 

Two ways:

  1. Craft your OAuth URL so it sends them back to the right page, or at least says next=url in the querystring. This is most reliable but can break (and does look ugly but who's copying and pasting OAuth URLs anyway?)

  2. Store a session containing the last requested "real" page. I say "real" like that because I don't count any auth/registration pages as real. So every hit, check to see what URL they're on, if it's not auth-related, store it in session. When they hit your OAuth-auccess page, redirect them to the session value. You can do this in a context processor or some middleware. Requires cookies and logout will nuke it.

Oli
Yeah, I'm doing the session thing. Just setting request.session['next'] = request.META['HTTP_REFERER'] in my login view before going to Twitter. I don't think Twitter will let me add dynamic querystrings to my return url although maybe I'm wrong on this.
Steve