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
Rails Form Object with Reform-Rails with Collections Not Working or Validating
How to Specify a Regex Character Range That Will Work in European Languages Other Than English
How to Remove a Row from a CSV with Ruby
Read and Write File Atomically
Should I Be Using Rails or Ruby for This Website Application? How
Conditional Page Caching [Solution: Conditional Fragment Caching]
Instance_Eval's Block Argument(S)- Documented? Purpose
Ruby Installation (2.2.2) Fails in MACos Big Sur
Ruby: Overriding the Puts Method
If 'Self' Is Always the Implied Receiver in Ruby, Why Doesn't 'Self.Puts' Work
Post Redirect Get Pattern in Rails
Ruby How to Merge Two CSV Files with Slightly Different Headers
How to Listen to Stdin Input Without Pausing My Script
Selenium2 Webdriver Ruby => How Click on a Hidden Link
How to Enable Colors with Rspec When Using Jruby or Bundle Exec