Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

Saving User Location

jjb edited this page May 31, 2011 · 3 revisions

Saving User Location

One of the more common things required of an authentication system is the ability to send the user back where they came. OmniAuth will automatically keep track of the HTTP_REFERER when you begin the authentication process, and will provide it to you in the callback phase as the omniauth.origin key in the environment hash. To use this, you would simply modify your callback action to redirect to the origin if it is already set:

class SessionsController < ApplicationController
  def callback
    # do your authentication stuff here...
    redirect_to request.env['omniauth.origin'] || '/default'
  end
end

How convenient!

You can also customize the return URL by providing the origin query parameter in your initial omniauth URL:

/auth/twitter?origin=%2Fusers%2Fshow%2F24