/ / Jak powinienem zintegrować dwustopniowe uwierzytelnianie Devise z kontrolerem niestandardowych sesji? - ruby-on-rails, ruby, ruby-on-rails-4, wymyślaj

Jak powinienem zintegrować dwustopniowe uwierzytelnianie Devise z kontrolerem niestandardowych sesji? - ruby-on-rails, ruby, ruby-on-rails-4, wymyślaj

Zintegrowaliśmy uwierzytelnianie dwuetapowe Houdini z istniejącą aplikacją szyn.
Po pierwsze nie mam żadnych niestandardowych session_controller, a następnie two_factor_authentication działa dobrze.
Ale podczas gdy ja pisałem niestandardowe tworzenie akcji w kontroler sesji, to nie jest uwierzytelnione przez two_factor_authentication.

Oto niestandardowy kod do tworzenia akcji kontrolera Sesji.

  if status_response.nil?
render :file => "public/api_not_found.html", :status => :not_found, :layout => false
else
if status_response["code"].to_i == 1
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
flash[:alert] = "Invalid Email ID or password."
yield if block_given?
respond_to_on_destroy
else
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_flashing_format?
sign_in(resource_name, resource)
yield resource if block_given?
respond_with resource, location: after_sign_in_path_for(resource)
end
end

Kod modelu user.rb:

  devise :two_factor_authenticatable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, password_length: 8..30
has_one_time_password


def send_two_factor_authentication_code
puts ">>>>>>>>>>>>>>> otp_secret_key: #{otp_secret_key}, otp_code: #{otp_code}"
end

Wiem, że jeśli dostosowujemy akcję tworzenia kontrolera Sesji, powinniśmy zadzwonić do two_factor_authentication. Próbowałem wywołać to w kontrolerze, ale powoduje to błąd.

Więc moje pytanie, jak powinienem zintegrować two_factor_authentication z niestandardowym tworzeniem akcji kontrolera sesji?

Odpowiedzi:

0 dla odpowiedzi № 1

Wygląda na to, że chciałem tylko użyć super.

    if status_response.nil?
render :file => "public/api_not_found.html", :status => :not_found, :layout => false
else
if status_response["code"].to_i == 1
#If this is true then I didn"t got auth_tok from API therefore i forcefully signed out the user.
else
super
end
end

Tak więc sprawdzam odpowiedź użytkownika i na tej podstawie chciałem zezwolić użytkownikowi na logowanie.
Inną rzeczą jest, że kod otp_code w bazie danych nie powinien być zerowy. Jeśli jest zerowy, to 2FA nie będzie działać. Po prostu przekierowuje go do roota bez pytania otp_code.