-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails Engine + OmniAuth = undefined method and no route matches #2692
Comments
You are right. This is wrong. If we are inside an engine, we most likely don't want the omniauth path prefix to reflect inside the engine. I am unsure on how to fix this for now so I recommend you to simply define the routes manually meanwhile: https://github.com/plataformatec/devise/blob/master/lib/devise/rails/routes.rb#L387-L397 |
Thanks for your answer and pointing me to the source of problems. I don't think, it's the best idea, but it fixed routes def devise_omniauth_callback(mapping, controllers) #:nodoc:
path, @scope[:path] = @scope[:path], nil
# path_prefix = Devise.omniauth_path_prefix || "/#{mapping.path}/auth".squeeze("/") # Temporary fixed
path_prefix, callback_prefix = Devise.omniauth_path_prefix, "/#{mapping.path}/auth".squeeze("/")
set_omniauth_path_prefix!(path_prefix)
providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s))
match "#{path_prefix}/:provider",
:constraints => { :provider => providers },
:to => "#{controllers[:omniauth_callbacks]}#passthru",
:as => :omniauth_authorize,
:via => [:get, :post]
match "#{callback_prefix}/:action/callback",
:constraints => { :action => providers },
:to => controllers[:omniauth_callbacks],
:as => :omniauth_callback,
:via => [:get, :post]
ensure
@scope[:path] = path
end This is how I actually fix that devise_scope :user do
providers = Regexp.union(Devise.omniauth_providers.map(&:to_s))
match 'users/auth/:provider',
constraints: { provider: providers },
to: 'omniauth_callbacks#passthru',
as: :omniauth_authorize,
via: [:get, :post]
match 'users/auth/:action/callback',
constraints: { action: providers },
to: 'omniauth_callbacks',
as: :omniauth_callback,
via: [:get, :post]
end
devise_for :users, class_name: 'Auth::User', module: :devise |
Hello, I have almost the same problem with
There is not any routes created and visible thanks to rake routes. I am not using an engine like previously. This code was working with Rails 3.2.12, Ruby 1.9.3, devise 2.2.3. Now I am using Rails 4.0.2, Ruby 2.1 and, obviously devise 3.2.2. |
Was also bit by this issue in 3.2.4. My workaround was to add this to routes (note I had to prefix helpers with devise_scope :user do
match "/users/auth/:provider",
constraints: { provider: /google|facebook/ },
to: "users/omniauth_callbacks#passthru",
as: :user_omniauth_authorize,
via: [:get, :post]
match "/users/auth/:action/callback",
constraints: { action: /google|facebook/ },
to: "users/omniauth_callbacks",
as: :user_omniauth_callback,
via: [:get, :post]
end and this to my Devise initializer: Rails.application.config.after_initialize do
::OmniAuth::config.path_prefix = config.omniauth_path_prefix = "#{Ares.path_prefix}/users/auth"
end where |
Thanks, @jirikolarik and @tmandry, the code worked for me too. But it would be nice if it worked without hacks, out of the box. =) |
Is this still working? I tried the solution mentioned here, but I got nothing. Also, looking at the solution here and the current code base, it looks like this was already implemented inside Devise. I've opened a question on SO: http://stackoverflow.com/questions/25151273/not-found-authentication-passthru-error-devise-omniauthable-module-doesnt |
For me, I didn't have this issue - maybe it's because I mounted my engine at the root level, per this article (see "Routes" section): Devise version: 3.2.4 # Main Routes
mount MyEngine::Engine, at: "/" # Model
module MyEngine
class Account < ActiveRecord::Base
devise :omniauthable, omniauth_providers: %I(google_oauth2)
end
end # Controller
module MyEngine
module Accounts
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
...
end
end
end
end # Config
config.omniauth_path_prefix = "/my_engine/accounts/auth" # Routes
MyEngine::Engine.routes.draw do
scope :my_engine do
devise_for :accounts, class_name: "MyEngine::Account",
module: :devise,
controllers: { omniauth_callbacks: "my_engine/accounts/omniauth_callbacks" } <!-- View -->
<%= link_to account_omniauth_authorize_path(provider: :google_oauth2) ... %> |
I have the same issue. Mounting engine that uses devise + oauth under different path than "/" causes "Not found, authentication pass thru" error. I've tried setting The workaround I've found is to mount engine at "/" and use namespaces, such as:
Devise 3.4.1, omniauth 1.2.2, rails 4.2.0. |
I have the same promble,and use @tmandry way,there is a place to watch.
|
I'm closing this issue because it has not had recent activity. |
I am getting The action 'facebook' could not be found for Devise::OmniauthCallbacksController And don't know how to even debug it... |
Hi, I just created RailsEngine with OmniAuth.
My engine is called Auth.
I added - lib/auth.rb
config/routes.rb
And I configured initializers/devise.rb like this
But when I visit /auth/users/sign_in, it raise error
So I rewrote view and linked it directly to '/auth/users/auth/twitter'
This redirects me to twitter and when I confirm the dialog, it redirects me back and raise
This route doesn't exist, but exist: '/auth/auth/users/auth/twitter/callback'
when I remove
then is callback route generated properly
But it raise
When I access '/auth/users/auth/twitter'
I'm running on Rails 4 and Ruby 2
The text was updated successfully, but these errors were encountered: