在临时/生产环境中,双因素身份验证代码不匹配

时间:2018-03-02 10:09:39

标签: ruby-on-rails-4 devise imagemagick minimagick two-factor-authentication

我在Rails4应用中设置了双因素身份验证。在我的开发环境中一切正常,但在Staging环境中失败了。我的暂存环境是运行NGINX Web服务器的Ubuntu 14.04 LTS。我已经安装了ImageMagick 6.7.7-10。虽然我的开发环境是macOS High Sierra,但我安装并运行了ImageMagick 7.0.6-7 THIN Web服务器。

RubyGems的:

gem 'devise', '~> 3.5', '>= 3.5.2'
gem 'devise-two-factor', '~> 2.2', '>= 2.2.1'
gem 'rqrcode-rails3', '~> 0.1.7'
gem 'mini_magick', '~> 4.5'

QRCode呈现在暂存上,但它与开发不同。我不确定这是不是一个案例。还有一件事是,可以通过Google身份验证器应用程序扫描QRCode,但是当我验证代码时,它失败了。在暂存中,我已在rails控制台中检查user.current_otp,它与我扫描的代码永远不匹配。但是在开发中,我扫描QRCode,我在我的rails控制台中执行user.current_otp时得到匹配代码。

我将QRCode渲染为svg图像。

<%= raw RQRCode::render_qrcode(current_user.otp_provisioning_uri(current_user.email, issuer: "2FA App"), :svg, level: :l, unit: 2) %>

如果您愿意,我将非常感谢您的帮助并提供更多详细信息。

1 个答案:

答案 0 :(得分:0)

如上述评论中所述,您需要设置NTP操作Staging Server并同步时间以及可能在手机上的Google身份验证器应用中同步时间:

在Ubuntu上安装NTP:

禁用timesyncd:

sudo timedatectl set-ntp no

验证是否已禁用timesyncd:

timedatectl

安装ntpd:

sudo apt-get install ntp

检查ntpd是否正在运行:

sudo ntpq -p

检查日期和时间:

date

将分钟和秒数与某些网站链接进行比较:https://www.timeanddate.com/

在Android / iOS Google身份验证器应用上同步时间:

https://support.google.com/accounts/answer/185834?hl=en

滚动到最底部:“我的Google身份验证器代码无效(Android)”

相关问题