【问题标题】:Omniauth CallbackOmniauth 回调
【发布时间】:2015-01-08 09:30:40
【问题描述】:

我正在使用我的 rails 4 应用程序。我使用 Facebook、LinkedIn 和电子邮件进行身份验证。

我刚刚开始使用 Figaro,我对代码所做的唯一更改是将用于我的电子邮件帐户的密码从 production.rb 交换到我的 application.yml 文件中。

现在,当我测试 LinkedIn 注册链接时,我收到一条错误消息,指出出现问题(在按“注册 LinkedIn”后)。当我尝试使用其他选项进行身份验证时,我得到了同样的错误。

我的全域身份验证回调控制器中的linkedin 出现回调错误。问题所在的行是下面的“@user.send_admin_email”:

def linkedin
    @user = User.find_for_linkedin_oauth(request.env["omniauth.auth"])
      if @user.persisted?
        @user.send_admin_mail

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

我设置了一个邮件程序,它会向我发送一封电子邮件,告诉我何时有新的注册。它使用我将密码从 production.rb 移动到 application.yml 的电子邮件地址

有谁知道如何解决这个错误?

非常感谢

【问题讨论】:

  • 在生产环境中,您需要将密钥传递给生产服务器。例如,你可以使用 figaro 和 heroku:figaro heroku:set -e production
  • 您好,感谢您的提示。我不确定我应该在哪里尝试这个?我应该在 production.rb 文件中的 config.action_mailer.smtp_settings 中添加一行吗?谢谢

标签: ruby-on-rails devise linkedin


【解决方案1】:

问题可能出在 application.yml 文件的文本编码上,尤其是当您的电子邮件密码中包含非标准字符时。尝试启动控制台,然后按照 to_s 的样子输出您的密码

p ENV['your_figaro_key'].to_s

看看这是否返回你所期望的

【讨论】:

  • Hi Houen - 我在尝试此操作时故意将其设置为一个简单的字符串,以避免识别字符的任何限制。感谢您的提示,但这对我来说不是错的。还是谢谢。
【解决方案2】:

嗯,这对我来说似乎是一个“强参数”问题。检查您的“send_admin_mail”,看看是否有“update_atributes”(或“save”)。

我猜你的 user.rb 是这样的:

class User < ActiveRecord::Base
...
attr_accessor :extras

def self.find_for_linkedin_oauth(access_token, signed_in_resource=nil)
  ...
  user = User.where(...)
  ...
  user.extras = access_token.extras
  ...
end

def send_admin_mail
  ...
  self.update_attributes(some_attribute: extras["some_attribute"])
  ...
end

如果您这样做,“保存”将尝试使用不允许的参数进行更新。正确的版本必须是这样的:

self.update_attributes(some_attribute: extras.permit(:some_attribute))

如果我没记错的话,第一个实现在以前版本的强参数中有效,但现在不行了。

【讨论】:

  • 嗨丹尼尔 - 我的发送电子邮件方法中没有更新或保存。我有:def send_admin_mail AdminMailer.new_user_waiting_for_approval(self).deliver end
  • 您能看到我应该添加的内容吗?非常感谢
  • 我的邮件有:def new_user_waiting_for_approval(user) @user = user mail(to: "www@www.com", from: "www@www.com", subject: "Registration Request # {user.first_name} #{user.last_name} ") 结束
  • 在你的 find_for_linkedin_oauth 中?您是否将参数保存在用户记录中?几周前我遇到了这样的问题:我有一个稳定的 Rails 4 应用程序,然后我更新了我的 gem,Facebook 登录崩溃了。几天前,Rails 团队改变了强参数的工作方式。
  • 对于任何可能遇到相同问题的人,我忘记将我的 .gitignore 文件从 application.yml 发布到 heroku,以便它具有身份验证详细信息。非常感谢您的帮助 - 我希望这对其他人有所帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多