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/passkey_auth/webauthn/credentials/challenges_controller.rb', line 13
def create
user = current_user || find_user_by_session_id
user.update(webauthn_id: ::WebAuthn.generate_user_id) unless user.webauthn_id
user_email = PasskeyAuth.user_email(user)
webauthn_name = params[:name].presence || user.try(:name) || user_email
create_options = ::WebAuthn::Credential.options_for_create(
user: {
id: user.webauthn_id,
display_name: webauthn_name,
name: user_email
},
exclude: user.webauthn_credentials.pluck(:external_id),
authenticator_selection: {
authenticator_attachment: "platform",
user_verification: "preferred",
resident_key: "required"
}
)
session[:webauthn_registration_challenge] = create_options.challenge
respond_to do |format|
format.json { render json: create_options }
end
end
|