【问题标题】:Rails - Linkedin Auth: Not found. Authentication passthruRails - Linkedin 身份验证:未找到。身份验证通道
【发布时间】:2021-09-21 12:20:05
【问题描述】:

您好,有一个使用 Linkedin 身份验证的应用程序,以前可以正常工作。今天我收到用户的抱怨,说他们看到:Not found. Authentication passthru. 当点击使用 Linkedin 登录时。它将他们带到页面:http://XXXXX/users/auth/linkedin?locale=en

当我检查日志时,我得到:

Started GET "/users/auth/linkedin?locale=en" for ::1 at 2021-07-12 18:04:13 +0800
Processing by OmniauthCallbacksController#passthru as HTML
  Parameters: {"locale"=>"en"}
  Rendering text template
  Rendered text template (0.0ms)
Completed 404 Not Found in 3ms (Views: 0.9ms | ActiveRecord: 0.3ms)

我的控制器看起来像:

class OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def linkedin

    @user = User.connect_to_linkedin(request.env["omniauth.auth"],current_user)
    if @user.persisted?
      flash[:notice] = I18n.t "devise.omniauth_callbacks.success"
      sign_in_and_redirect @user, :event => :authentication
    else
      session["devise.linkedin_uid"] = request.env["omniauth.auth"].except("extra")
      redirect_to new_user_registration_url
      flash[:notice] = I18n.t "devise.omniauth_callbacks.failure"

    end
  end

我的模型中有以下内容:

设计 :database_authenticable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable, :omniauth_providers => [:linkedin

             user_linkedin_omniauth_authorize GET|POST /users/auth/linkedin(.:format)                                                omniauth_callbacks#passthru
              user_linkedin_omniauth_callback GET|POST /users/auth/linkedin/callback(.:format)                                       omniauth_callbacks#linkedin

当我将POST 方法添加到link_to 时,我得到以下信息:

Started POST "/users/auth/linkedin?locale=en" for ::1 at 2021-07-12 21:56:18 +0800
D, [2021-07-12T21:56:18.416654 #65475] DEBUG -- omniauth: (linkedin) Request phase initiated.
W, [2021-07-12T21:56:18.417955 #65475]  WARN -- omniauth: Attack prevented by OmniAuth::AuthenticityTokenProtection
E, [2021-07-12T21:56:18.418089 #65475] ERROR -- omniauth: (linkedin) Authentication failure! authenticity_error: OmniAuth::AuthenticityError, Forbidden
Processing by OmniauthCallbacksController#failure as HTML

还有其他的

请问您知道这个突然出现的问题背后的原因是什么吗? 几天前我做了一个捆绑更新,开始出现很多错误。

到目前为止我所看到的都无济于事。

【问题讨论】:

  • 404错误从何而来?
  • 您是否尝试过使用 POST 请求而不是 GET 来访问端点?如果您最近更新,可能是您现在需要 POST(请参阅github.com/omniauth/omniauth/issues/960 - 还有这个 gem 可以帮助您github.com/cookpad/omniauth-rails_csrf_protection)
  • 我不知道,这个工具我从来没有遇到过任何问题。我正在寻找可能的原因。
  • @johansenja,我添加了 gem 并修改了 link_to,所以我设法让用户进入 Linkedin 身份验证页面,但是在返回我的应用程序的路上,它需要用户进入设计登录页面并显示:错误——omniauth:(linkedin)身份验证失败! csrf_detected: OmniAuth::Strategies::OAuth2::CallbackError, csrf_detected |检测到 CSRF
  • 您是否在请求中包含 CSRF 令牌?您可以执行类似 之类的操作,这会将您的按钮变成带有必要令牌的表单

标签: ruby-on-rails omniauth


【解决方案1】:

在application.rb 中,您的config.load_defaults 设置是什么?如果将其设置为6.1,我自己就会遇到问题。 6.0 工作正常。它与 cookie SameSite 设置相关的一些问题(对于 localhost 需要宽松,通常在网络上实时使用 none+secure - 我可能是错的)。
而且是的,请检查您是否正在使用 CSRF 检查到位来对您的登录端点进行 POST。

【讨论】:

    猜你喜欢
    • 2015-01-30
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2015-09-23
    相关资源
    最近更新 更多