问题描述
我将此devise-jwt
与devise集成在一起,并且效果很好。但是现在我添加了2FA
,并且OTP
验证失败时响应出现问题。
我遵循了此guide的要求,添加了2FA,并调整了会话控制器的创建动作,如下所示。
这是会话控制器
我收到的参数是电子邮件,密码和OTP
# frozen_string_literal: true
class Api::Customers::V1::Auth::SessionsController < Devise::SessionsController
def create
self.resource = warden.authenticate!(auth_options)
if resource
if params[:customer][:otp_code_token].size > 0
if resource.authenticate_otp(params[:customer][:otp_code_token],drift: 60)
continue_sign_in(resource,resource_name)
super { @token = current_token } #for token in body as expected by front-end
else
# How to throw unauthorized here (devise-jwt)???????????????????????????
sign_out resource
end
end
end
end
private
def current_token
request.env['warden-jwt_auth.token']
end
def continue_sign_in(resource,resource_name)
sign_in(resource_name,resource)
yield resource if block_given?
respond_with resource,location: after_sign_in_path_for(resource)
end
end
如果传递了正确的email
,password
和otp
,则上述代码按预期工作。但是,如果响应中传递了错误的otp
,则我得到的错误是{ {1}},而不是200(:ok)
。我们如何发送未经授权的自定义消息(如:unauthorized
)
我知道它不是错误。但是如何做出回应otp invalid. Please try again.
??
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)