Search code examples
ruby-on-railsfacebookparametersomniauthomniauth-facebook

How can I pass parameters through a Omniauth/Facebook login request?


I integrated the omniauth-facebook gem with devise. I got sign up and sign in to work, but I can't figure out how to pass additional parameters through to the facebook callback method in RegistrationsController, for example the url the user started the sign up process on.

Parameters I include in the initial url (for example, localhost:3000/auth/facebook?url="url") are not passed through to my facebook method in my Registrations controller.

erb link

<%= link_to "fb", facebook_omniauth_path(url: "url") %>

routes

get 'auth/facebook', as: 'facebook_omniauth'
get 'auth/facebook/callback' => 'registrations#facebook'

controller

  def facebook
    @user = User.from_omniauth(request.env["omniauth.auth"])
    if @user.persisted?
      redirect_to root_path
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end

Does anyone know how I can use the url parameter in my facebook method?


Solution

  • The omniauth.auth does not display the additional parameters by default. You need to use omniauth.params instead to retrieve url value like below.

    request.env["omniauth.params"]["url"]