about summary refs log tree commit diff
path: root/app/controllers/auth
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-08-30 18:34:51 +0200
committerGitHub <noreply@github.com>2020-08-30 18:34:51 +0200
commitf715e8b51612820a18fa307e4465eb0c1a088f86 (patch)
tree8137b48a716e05424ca544210d86e91818085ba7 /app/controllers/auth
parent30632adf9eda6d83a9b4269f23f11ced5e09cd93 (diff)
parenta68ec50e4e38898e88a7dcc33bd0032adc946dda (diff)
Merge pull request #1411 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/controllers/auth')
-rw-r--r--app/controllers/auth/sessions_controller.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/app/controllers/auth/sessions_controller.rb b/app/controllers/auth/sessions_controller.rb
index 441833e85..1cf6a0a59 100644
--- a/app/controllers/auth/sessions_controller.rb
+++ b/app/controllers/auth/sessions_controller.rb
@@ -39,6 +39,22 @@ class Auth::SessionsController < Devise::SessionsController
     store_location_for(:user, tmp_stored_location) if continue_after?
   end
 
+  def webauthn_options
+    user = find_user
+
+    if user.webauthn_enabled?
+      options_for_get = WebAuthn::Credential.options_for_get(
+        allow: user.webauthn_credentials.pluck(:external_id)
+      )
+
+      session[:webauthn_challenge] = options_for_get.challenge
+
+      render json: options_for_get, status: :ok
+    else
+      render json: { error: t('webauthn_credentials.not_enabled') }, status: :unauthorized
+    end
+  end
+
   protected
 
   def find_user
@@ -53,7 +69,7 @@ class Auth::SessionsController < Devise::SessionsController
   end
 
   def user_params
-    params.require(:user).permit(:email, :password, :otp_attempt, :sign_in_token_attempt)
+    params.require(:user).permit(:email, :password, :otp_attempt, :sign_in_token_attempt, credential: {})
   end
 
   def after_sign_in_path_for(resource)