title: OmniAuth: redirect to page which requires authentication instead of the one which user came from
body: <p>There are some pages in my app which require authentication with linked in. I use before filter to redirect user to <code>/auth/linked_in</code> if s/he is not already authenticated. I want that after authentication user should be redirected to page which required authentication instead of page from which user came from.</p>
  
  <p>Before filter looks like:</p>
  
  <pre><code>def require_linked_in!
    unless current_user and current_user.linked_in_authenticated?
      redirect_to "/auth/#{Authentication::LINKED_IN}"
    end
  end
  </code></pre>
  
  <p>In my omniauth callback I do some stuff, like logging in or associating provider data with user account and if everything was ok, <code>redirect_to request.env['omniauth.origin'] || root_url</code>, but this redirects back the user to page from which he clicked the link to page requiring linked_in authentication and not the target page.</p>
  
  <p>How can I redirect the user to page which triggered authentication instead of page which user came from?</p>
  
  <p>PS: User can only sign up using the registration form for the app, but can later on connect there linked and facebook profile and also use them instead of normal email/password login form. If it makes any difference.</p>