Devise Omniauthable Breaks Omniauth Authentication with 'Could Not Find a Valid Mapping for Path'

Devise omniauthable breaks Omniauth authentication with `Could not find a valid mapping for path`

Answering my own question. So, final decision was to go with pure Omniauth implementation. I removed :omniauthable from User model, removed config.omniauth... from devise.rb, removed :omniauth_callbacks devise routes from routes.rb.
So, all users (no matter what role) would use ame callback routes and hit sessions_controller#authenticate_jobseeker action (should consider renaming the action?):

def authenticate_jobseeker
auth_hash = request.env['omniauth.auth']

unless auth_hash.present?
redirect_to request.env['omniauth.origin'] || root_path, alert: "Sorry, we were not able to authenticate you" and return
end

@user = User.find_from_oauth(auth_hash)
if @user.present?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication and return
else
session[:jobseeker] = auth_hash["info"]
if valid_job_seeker?
redirect_to new_job_application_path(...)
end
end
end

and User.find_from_oauth:

def self.find_from_oauth(auth_hash)
if auth_hash
user = User.where(:email => auth_hash["info"]["email"]).first
end
user
end

This implementation satisfied all of the requirements.

Devise + Omniauth = undefined method `new_session_path'

What version of devise are you running? This closed issue seem to deal with the same problem, and assumes that it was gonna be fixed in version 1.4.9 and offers a quick and dirty fix.

But, if it doesn't help, try to change the named route for new session to:

get 'sign_in', :to => 'users/sessions#new', :as => :new_session

Also, I asked the question about Devise with Omniauth that you may find useful: Devise omniauthable breaks Omniauth authentication with `Could not find a valid mapping for path`

Callback for Omniauth-Trello (RoR) - can't sign in

The error is right there in your log:
Authentication failure! service_unavailable: Net::HTTPFatalError, 500 "Internal Server Error"

Your callback isn't being hit because you've inserted the OmniAuth::Builder middleware. You could try removing that and inspecting the params that are sent along with the callback.

Once you're removed the middleware you can drop a byebug or a binding.pry at the top of your callback action. Once you're in the debugger check the value of request.env['omniauth.auth']. That should give you some insight as to what the problem is. Hard to say more without knowing more about the environment.

Check if user is valid for authentication only if uses database authenticable

You can check below method before executing active_for_authentication? lines

The below lines will If the returned some res data if login using omniauth add logic unless res.present?

def logged_using_omniauth? request
res = nil
omniauth = request.env["omniauth.auth"]
res = Authentication.find_by_provider_and_uid
(omniauth['provider'], omniauth['uid']) if omniauth
res
end

Prevent user from accessing /auth/:provider under some conditions in OmniAuth

Ok, the solution I found was to create a new OmniAuth Strategy which inherits from the one I wanted to use and to override the request_phase method. Could not get the same behaviour using only OmniAuth configs in its initializer.

def request_phase
if env['rack.session']['warden.user.user.key'].present?
super
else
redirect '/'
end
end

Devise Authentication for users from Multiple GApps Domains

This doesn't seem like it'll work. I did a deep dive into the gem code and it only supports one domain.

I'm going to switch to open id instead.



Related Topics



Leave a reply



Submit