【发布时间】:2021-03-30 08:48:22
【问题描述】:
我无法在我的生产网站上通过 LinkedIn 注册用户。它显示这样的错误:
Completed 500 Internal Server Error in 202ms (ActiveRecord: 3.8ms)
[f842309d-189a-4edc-bafb-a6a567ea8fcd]
[f842309d-189a-4edc-bafb-a6a567ea8fcd] BCrypt::Errors::InvalidHash (invalid hash):
[f842309d-189a-4edc-bafb-a6a567ea8fcd]
[f842309d-189a-4edc-bafb-a6a567ea8fcd] app/models/user.rb:82:in `from_omniauth'
[f842309d-189a-4edc-bafb-a6a567ea8fcd] app/controllers/users/omniauth_callbacks_controller.rb:9:in `linkedin'
它在我的本地机器上运行良好。
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def linkedin
@user = User.from_omniauth(auth_hash, current_user, session)
remember_me(@user)
session[:user_id] = @user.id
if !(@user.img_url == auth_hash.info.picture_url)
@user.update_attributes(:img_url => auth_hash.info.picture_url)
end
if not @user.persisted?
session["devise.linkedin_data"] = auth_hash
render body: session.to_json
end
sign_in_and_redirect(:user, @user)
end
end
用户模型
def self.from_omniauth(auth, signed_in=nil, session)
user.password = Devise.friendly_token unless user.encrypted_password.present?
end
有人可以帮我理解这个错误以及我可以如何解决它吗?
【问题讨论】:
-
嘿,你为什么将 Devise.friendly_token 设为链接登录的密码?生成一个随机密码以使设计满意。 SecureRandom.uuid 或类似的东西
-
@SimonFranzen 我们也将设计用于用户登录,我什至尝试使用安全随机数,但它抛出了同样的错误。 user.password = SecureRandom.urlsafe_base64 除非 user.encrypted_password.present?
标签: ruby-on-rails ruby ruby-on-rails-5 bcrypt