从devise-jwt中的会话控制器发出未经授权的请求

问题描述

我将此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

如果传递了正确的emailpasswordotp,则上述代码按预期工作。但是,如果响应中传递了错误otp,则我得到的错误是{ {1}},而不是200(:ok)。我们如何发送未经授权的自定义消息(如:unauthorized

我知道它不是错误。但是如何做出回应otp invalid. Please try again. ??

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...