Sha256: 890b674756c219eea81473b29533566f29274ba3236d5bf31a2d101c9f369bdd
Contents?: true
Size: 1.27 KB
Versions: 8
Compression:
Stored size: 1.27 KB
Contents
class TwoFactorAuthentication::Challenge::SecurityKeysController < ApplicationController skip_before_action :authenticate before_action :set_user def new respond_to do |format| format.html format.json { render json: options_for_get } end end def create if @user.security_keys.exists?(external_id: credential.id) sign_in_and_redirect_to_root else render json: { error: "Verification failed: #{e.message}" }, status: :unprocessable_entity end end private def set_user @user = User.find_signed!(session[:challenge_token], purpose: :authentication_challenge) rescue StandardError redirect_to sign_in_path, alert: "That's taking too long. Please re-enter your password and try again" end def sign_in_and_redirect_to_root session = @user.sessions.create! cookies.signed.permanent[:session_token] = { value: session.id, httponly: true } render json: { status: "ok", location: root_url }, status: :created end def options_for_get WebAuthn::Credential.options_for_get(allow: external_ids) end def external_ids @user.security_keys.pluck(:external_id) end def credential @credential ||= WebAuthn::Credential.from_get(params.require(:credential)) end end
Version data entries
8 entries across 8 versions & 1 rubygems