Devise + OmniAuth Instagram: Not found. Authentication passthru

时间:2022-07-18 00:13:37

So I've found similar questions on this site with not a really direct solution to this problem that I'm seeing.

所以我在这个网站上发现了类似的问题,并没有真正直接解决我遇到的这个问题。

I'm using omniauth-instagram and omniauth-facebook with devise and getting the error below (with both providers).

我正在使用omniauth-instagram和omniauth-facebook与设计并获得下面的错误(与两个提供商)。

URL: http://localhost:3000/users/auth/callbacks/facebook
Error: Not found. Authentication passthru.

URL:http:// localhost:3000 / users / auth / callbacks / facebook错误:未找到。身份验证passthru。

Below are examples of my callbacks_controller.rb, user.rb and routes.rb -- Any helpful tips in the right direction are much appreciated. Let me know if I should provide any other information!

以下是我的callbacks_controller.rb,user.rb和routes.rb的示例 - 非常感谢任何有用的提示。如果我应该提供任何其他信息,请告诉我!

callbacks_controller.rb

callbacks_controller.rb

class Users::Auth::CallbacksController < Devise::OmniauthCallbacksController

  def instagram

      # You need to implement the method below in your model (e.g. app/models/user.rb)
      @user = User.find_for_oauth(request.env["omniauth.auth"], current_users)

      if @user.persisted?
        sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
        set_flash_message(:notice, :success, :kind => "Instagram") if is_navigational_format?
      else
        session["devise.instagram_data"] = request.env["omniauth.auth"]
        redirect_to new_user_registration_url
      end

  end




  def facebook

      # You need to implement the method below in your model (e.g. app/models/user.rb)
      @user = User.find_for_oauth(request.env["omniauth.auth"], current_users)

      if @user.persisted?
        sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
        set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format?
      else
        session["devise.facebook_data"] = request.env["omniauth.auth"]
        redirect_to new_user_registration_url
      end

  end


end

user.rb

user.rb

class User < ActiveRecord::Base

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  devise  :omniauthable, :omniauth_providers => [:instagram, :facebook]

  def self.find_for_oauth(auth, signed_in_resource = nil)

    # Get the identity and user if they exist
    identity = Identity.find_for_oauth(auth)
    user = identity.user

    if user.nil?

      # Get the existing user from email if the OAuth provider gives us an email
      user = User.where(:email => auth.info.email).first if auth.info.email

        # Create the user if it is a new registration
        if user.nil?
          user = User.new(
            name: auth.extra.raw_info.name,
            #username: auth.info.nickname || auth.uid,
            email: auth.info.email.blank? ? TEMP_EMAIL : auth.info.email,
            password: Devise.friendly_token[0,20]
          )
          user.skip_confirmation!
          user.save!
        end

        # Associate the identity with the user if not already
        if identity.user != user
          identity.user = user
          identity.save!
        end

    end

    user


  end
end

routes.rb
devise_for :users, :controllers => { :omniauth_callbacks => "users/auth/callbacks" }

routes.rb devise_for:users,:controllers => {:omniauth_callbacks =>“users / auth / callbacks”}

2 个解决方案

#1


0  

Did you add both in devise.rb?

你在devise.rb中添加了两个吗?

  # devise.rb
  # ...

  # ==> OmniAuth
  # Add a new OmniAuth provider. Check the wiki for more information on setting
  # up on your models and hooks.
  # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'

  config.omniauth :facebook, "KEY", "SECRET"
  config.omniauth :instagram, "KEY", "SECRET"

#2


0  

After configuring your strategy, you need to make your model (e.g. app/models/user.rb) omniauthable:

配置策略后,您需要使您的模型(例如app / models / user.rb)具有可扩展性:

devise :omniauthable, :omniauth_providers => [:facebook, :instagram]

设计:omniauthable,:omniauth_providers => [:facebook,:instagram]

#1


0  

Did you add both in devise.rb?

你在devise.rb中添加了两个吗?

  # devise.rb
  # ...

  # ==> OmniAuth
  # Add a new OmniAuth provider. Check the wiki for more information on setting
  # up on your models and hooks.
  # config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'

  config.omniauth :facebook, "KEY", "SECRET"
  config.omniauth :instagram, "KEY", "SECRET"

#2


0  

After configuring your strategy, you need to make your model (e.g. app/models/user.rb) omniauthable:

配置策略后,您需要使您的模型(例如app / models / user.rb)具有可扩展性:

devise :omniauthable, :omniauth_providers => [:facebook, :instagram]

设计:omniauthable,:omniauth_providers => [:facebook,:instagram]