【发布时间】:2018-04-27 11:42:12
【问题描述】:
我正在尝试使用devise-authy gem 通过authy 2FA of twilio 实现两因素身份验证。
我想为 2FA 自定义包含三个页面的视图。
第一页 - 我的登录页面,用户输入
username和password,on submit它将被重定向到一个页面-
第二页 - 在此页面中,他可以选择2FA方法通过电话或短信接收代码,然后重定向
第三页 - 他终于在这里输入了代码。
我可以配置前两个页面。
我的问题是在第三页,我设置authy form 进行代码验证,我得到错误 undefined method id for nil class
<%= verify_authy_form do %>
<legend><%= I18n.t('submit_token_title', {:scope => 'devise'}) %></legend>
<%= label_tag :token %>
<%= text_field_tag :token, "", :autocomplete => :off, :id => 'authy-token' %>
<label>
<%= check_box_tag :remember_device %>
<span><%= I18n.t('remember_device', {:scope => 'devise'}) %></span>
</label>
<!-- Help tooltip -->
<!-- You need to configure a help message. -->
<!-- See documentation: https://github.com/authy/authy-form-helpers#help-tooltip -->
<!-- <%= link_to '?', '#', :id => 'authy-help' %> -->
<%= authy_request_sms_link %>
<%= authy_request_phone_call_link %>
<%= submit_tag I18n.t('submit_token', {:scope => 'devise'}), :class => 'btn' %>
<% end %>
verify_authy_form 这一行出现错误
在检查 gem 的代码时,我发现我需要 @authy_id 所以我尝试了
<%@authy_id=User.find(session[:user_id]).authy_id%>
鉴于没有仍然没有成功。
这是我的Users::AuthyCustomController,我已经覆盖了 gem 中所述的一些方法
class Users::AuthyCustomController < Devise::DeviseAuthyController
protected
def after_authy_enabled_path_for(resource)
my_own_path
end
def after_authy_verified_path_for(resource)
my_own_path
end
def after_authy_disabled_path_for(resource)
my_own_path
end
def invalid_resource_path
my_own_path
end
def authentication_sms
end
def authentication_phone
@authy_id=User.find(session[:user_id]).authy_id
# redirect_to user_verify_authy_path
# redirect_to user_verify_authy_path and return
end
end
我用谷歌搜索了,但我无法找到解决方案
【问题讨论】:
-
twilio.com/docs/api/authy#authy-api
verify_authy_form是一个助手,所以我想知道在哪里可以阅读该代码,我找不到这个特定项目的 github 页面
标签: ruby-on-rails devise twilio two-factor-authentication authy