Class: ActionAuth::WebauthnCredentialsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ActionAuth::WebauthnCredentialsController
- Defined in:
- app/controllers/action_auth/webauthn_credentials_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/action_auth/webauthn_credentials_controller.rb', line 31 def create webauthn_credential = WebAuthn::Credential.from_create(params) begin webauthn_credential.verify(session[:current_challenge]) credential = current_user.webauthn_credentials.build( external_id: webauthn_credential.id, nickname: params[:credential_nickname], public_key: webauthn_credential.public_key, sign_count: webauthn_credential.sign_count, key_type: key_type ) if credential.save render json: { status: "ok" }, status: :ok else render json: "Couldn't add your Security Key", status: :unprocessable_entity end rescue WebAuthn::Error => e Rails.logger.error "❌ Verification failed: #{e.}" render json: "Verification failed: #{e.}", status: :unprocessable_entity end end |
#destroy ⇒ Object
56 57 58 59 60 |
# File 'app/controllers/action_auth/webauthn_credentials_controller.rb', line 56 def destroy current_user.webauthn_credentials.destroy(params[:id]) redirect_to sessions_path end |
#new ⇒ Object
5 6 |
# File 'app/controllers/action_auth/webauthn_credentials_controller.rb', line 5 def new end |
#options ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/action_auth/webauthn_credentials_controller.rb', line 8 def if current_user.webauthn_id.blank? current_user.update!(webauthn_id: WebAuthn.generate_user_id) end = WebAuthn::Credential.( user: { id: current_user.webauthn_id, name: current_user.email }, exclude: current_user.webauthn_credentials.pluck(:external_id) ) session[:current_challenge] = .challenge respond_to do |format| format.json { render json: } if defined?(Turbo) format.turbo_stream { render json: } end end end |