Class: Devise::FidoUsfRegistrationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Devise::FidoUsfRegistrationsController
- Defined in:
- app/controllers/devise/fido_usf_registrations_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #new ⇒ Object
-
#show ⇒ Object
Show a list of all registered devices.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/devise/fido_usf_registrations_controller.rb', line 35 def create begin response = U2F::RegisterResponse.load_from_json(params[:response]) reg = u2f.register!(session[:challenges], response) pubkey = reg.public_key pubkey = Base64.decode64(reg.public_key) unless pubkey.bytesize == 65 && pubkey.byteslice(0) != "\x04" @device = FidoUsf::FidoUsfDevice.create!( user: resource, name: "Token ##{resource.fido_usf_devices.count + 1}", certificate: reg.certificate, key_handle: reg.key_handle, public_key: pubkey, counter: reg.counter, last_authenticated_at: Time.now ) flash[:success] = I18n.t('fido_usf.flashs.device.registered') rescue U2F::Error => e @error_message = "Unable to register: #{e.class.name}" flash[:error] = @error_message ensure session.delete(:challenges) end respond_with resource, location: after_sign_in_path_for(resource) end |
#destroy ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/devise/fido_usf_registrations_controller.rb', line 21 def destroy device = resource.fido_usf_devices.find(params[:id]) @fade_out_id = device.id unless params[:on_success_redirect_to] device.destroy unless params[:on_success_redirect_to] @devices = resource.fido_usf_devices.all end flash[:success] = I18n.t('fido_usf.flashs.device.removed') respond_to do |format| format.js format.html { redirect_to fido_usf_registration_url } end end |
#new ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'app/controllers/devise/fido_usf_registrations_controller.rb', line 6 def new @registration_requests = u2f.registration_requests session[:challenges] = @registration_requests.map(&:challenge) key_handles = resource.fido_usf_devices.map(&:key_handle) @sign_requests = u2f.authentication_requests(key_handles) @app_id = u2f.app_id render :new end |
#show ⇒ Object
Show a list of all registered devices
16 17 18 19 |
# File 'app/controllers/devise/fido_usf_registrations_controller.rb', line 16 def show @devices = resource.fido_usf_devices.all render :show end |
#update ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'app/controllers/devise/fido_usf_registrations_controller.rb', line 63 def update device = resource.fido_usf_devices.find(params[:id]) device.update!(fido_usf_params) respond_to do |format| format.js format.html { redirect_to fido_usf_registration_url } end end |