13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/controllers/devise/fido_usf_authentications_controller.rb', line 13
def create
begin
response = U2F::SignResponse.load_from_json(params[:response])
rescue TypeError
return redirect_to root_path
end
registration = @resource.fido_usf_devices
.find_by(key_handle: response.key_handle)
return 'Need to register first' unless registration
begin
u2f.authenticate!(session[:"#{resource_name}_u2f_challenge"], response,
registration.public_key, registration.counter)
registration.update(counter: response.counter,
last_authenticated_at: Time.now)
@resource.remember_me = Devise::TRUE_VALUES.include?(session[:"#{resource_name}_remember_me"]) if @resource.respond_to?(:remember_me=)
sign_in(resource_name, @resource)
set_flash_message(:notice, :signed_in) if is_navigational_format?
rescue U2F::Error => e
flash[:error] = "Unable to authenticate: #{e.class.name}"
return redirect_to root_path
ensure
session.delete(:"#{resource_name}_u2f_challenge")
end
respond_with resource, location: after_sign_in_path_for(@resource)
end
|