Pregunta

Say I have a restful resource, UserSession

> POST /user_sessions.json
{
    "user_session": {
        "user": {
            "some_key": "some_value",
            "some_other_key": "some_other_value"
        }
    }
}

I'd like to choose the provider in the UserSessions#create based on the params supplied, rather than using the /auth/:provider OmniAuth normally uses. Is it possible to do this?

¿Fue útil?

Solución

i am using a technique to set some omniauth options into the user-session.

i guess that this might work for your solution as well. you still have use the /auth/:provider routes though!

so i am basically linking all login urls to my auth_path

# routes.rb
get '/auth/login/:provider',          to: 'sessions#auth',     as: :auth

once i extract the data and put it into the session, i redirect the user to the right login path. in your case, it would need to extract the data from the params and then redirect:

# sessions_controller.rb
def auth
  session[:omniauth_keys] = Usergroup.omniauth_keys(params[:provider], request)
  redirect_to "/auth/#{params[:provider]}"
end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top