Class: TwoFactorAuth::AuthenticationsController

Inherits:
TwoFactorAuthController show all
Includes:
AuthenticationsHelper
Defined in:
app/controllers/two_factor_auth/authentications_controller.rb

Instance Method Summary collapse

Methods included from AuthenticationsHelper

#authentication_request, #clear_pending_challenge

Methods included from ApplicationHelper

#user_two_factor_auth_authenticated!, #user_two_factor_auth_authenticated?, #user_two_factor_auth_registered?

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/two_factor_auth/authentications_controller.rb', line 11

def create
  keyHandle = TwoFactorAuth::websafe_base64_decode(params.fetch(:keyHandle, ''))
  registration = Registration.find_by_key_handle(keyHandle)

  verifier = AuthenticationVerifier.new({
    registration: registration,
    request: authentication_request,
    client_data: ClientData.new(encoded: params[:clientData], correct_typ: 'navigator.id.getAssertion'),
    response: AuthenticationResponse.new(encoded: params[:signatureData]),
  })
  clear_pending_challenge

  if verifier.valid?
    user_two_factor_auth_authenticated! verifier.counter
    redirect_to (current_user)
  else
    flash[:alert] = "Unable to authenticate"
    render :new, status: 406
  end
end

#newObject



7
8
9
# File 'app/controllers/two_factor_auth/authentications_controller.rb', line 7

def new
  redirect_to (current_user) if user_two_factor_auth_authenticated?
end