Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

override "/auth/identity"-page of omniauth identity

I'm using omniauth without devise for authentication, as I like it's simplicity. In addition to omniauth-facebook I use omniauth-identity to offer email/pw-authentication.
The railscast on omniauth-identity describes how to setup a customized registration and login page. But the default routes supplied by identity (/auth/identity and /auth/identity/register) are still accessible.

I would like to have these under my control, as I want only want to let invited users register. Is there any way to override those routes supplied by a rack middleware?
Trying to just

match "/auth/identity", to: "somewhere#else"

doesn't do the trick!

Is there maybe a configuration to turn these default routes off? The documentation isn't giving any details on this...

Unfortunately I'm fairly new to Rack, so I don't have enough insight yet, to solve this issue on my own!
I'd be glad, if someone could point me in the right direction!

like image 921
wdspkr Avatar asked Jan 13 '12 17:01

wdspkr


3 Answers

An OmniAuth strategy object has a method request_phase which generates a html form and shows it to user. For "omniauth-identity" strategy this would be the form you see at /auth/identity url.

You can override the request_phase method and replace the form generator with, for example, a redirect to your custom login page (assuming you have it available at /login url). Place the following along with your omniauth initialization code:

module OmniAuth
  module Strategies
   class Identity
     def request_phase
       redirect '/login'
     end
   end
 end
end

# Your OmniAuth::Builder configuration goes here...
like image 122
1gor Avatar answered Sep 21 '22 02:09

1gor


In addition to 1gors and iains answer:

"/auth/identity/register" is served with GET as well, to override, I had to:

class OmniAuth::Strategies::Identity
  alias :original_other_phase :other_phase
  def other_phase
    if on_registration_path? && request.get?
      redirect '/sign_up'
    else
      original_other_phase
    end
  end
end
like image 29
svoop Avatar answered Sep 18 '22 02:09

svoop


You can set method in omniauth.rb

:on_login => SessionsController.action(:new)

for example:

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :identity,
           :fields => [:nickname],
           :on_login => SessionsController.action(:new),
           :on_registration => UsersController.action(:new),
           :on_failed_registration => SessionsController.action(:registration_failure)
end
like image 33
Serhiy Nazarov Avatar answered Sep 19 '22 02:09

Serhiy Nazarov