Override the "/ auth / identity" page of the omni identifier

I use omniauth without creating for authentication, as I like simplicity. In addition to omniauth-facebook, I use omniauth-identity to provide email / pw authentication.
railscast on omniauth-identity describes how to set up a custom registration and login page. But the default routes provided by the identifier (/ auth / identity and / auth / identity / register) are still available.

I would like them to be under my control, as I want only want the invited users to register. Is there a way to redefine the routes provided by the rack middleware?
The attempt is simple

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

doesn't do the trick!

Maybe the configuration will disable these routes by default? The documentation does not give any details about this ...

Unfortunately, I'm pretty new to Rack, so I don’t have enough information to solve this problem myself!
I would be happy if someone could point me in the right direction!

+6
source share
3 answers

The OmniAuth strategy OmniAuth has a request_phase method that generates an html form and displays it to the user. For the omniauth-identity strategy, this will be the form you see at /auth/identity url.

You can override the request_phase method and replace the form generator, for example, by redirecting to your user login page (if you have access to the /login URL). Put the following along with omniauth initialization code:

 module OmniAuth module Strategies class Identity def request_phase redirect '/login' end end end end # Your OmniAuth::Builder configuration goes here... 
+6
source

In addition to 1gors and iains answers:

"/ auth / identity / register" is also served with GET, 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 
+4
source

You can set the method in omniauth.rb

 :on_login => SessionsController.action(:new) 

eg:

 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 
+1
source

Source: https://habr.com/ru/post/905931/


All Articles