Skip to content

Commit

Permalink
Use residentKey instead of requireResidentKey (#74)
Browse files Browse the repository at this point in the history
* Use `residentKey` instead of `requireResidentKey`

* typo

* provide requireResidentKey as well, just in case

* Set require true only when r.key == required
  • Loading branch information
peaceful-james authored Jul 11, 2024
1 parent 054e245 commit 38a1253
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/webauthn_components/registration_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule WebauthnComponents.RegistrationComponent do
- `@class` (Optional) CSS classes for overriding the default button style.
- `@disabled` (Optional) Set to `true` when the `SupportHook` indicates WebAuthn is not supported or enabled by the browser. Defaults to `false`.
- `@id` (Optional) An HTML element ID.
- `@require_resident_key` (Optional) Set to `false` to allow non-passkey credentials. Defaults to `true`.
- `@resident_key` (Optional) Set to `:preferred` or `:discouraged` to allow non-passkey credentials. Defaults to `:required`.
## Events
Expand Down Expand Up @@ -59,7 +59,7 @@ defmodule WebauthnComponents.RegistrationComponent do
|> assign_new(:class, fn -> "" end)
|> assign_new(:webauthn_user, fn -> nil end)
|> assign_new(:disabled, fn -> false end)
|> assign_new(:require_resident_key, fn -> true end)
|> assign_new(:resident_key, fn -> :required end)
|> assign_new(:display_text, fn -> "Sign Up" end)
|> assign_new(:show_icon?, fn -> true end)
|> assign_new(:relying_party, fn -> nil end)
Expand Down Expand Up @@ -112,13 +112,7 @@ defmodule WebauthnComponents.RegistrationComponent do

def handle_event("register", _params, socket) do
%{assigns: assigns, endpoint: endpoint} = socket

%{
app: app_name,
id: id,
require_resident_key: require_resident_key,
webauthn_user: webauthn_user
} = assigns
%{app: app_name, id: id, resident_key: resident_key, webauthn_user: webauthn_user} = assigns

if not is_struct(webauthn_user, WebauthnUser) do
raise "user must be a WebauthnComponents.WebauthnUser struct."
Expand All @@ -139,7 +133,8 @@ defmodule WebauthnComponents.RegistrationComponent do
challenge: Base.encode64(challenge.bytes, padding: false),
excludeCredentials: [],
id: id,
require_resident_key: require_resident_key,
residentKey: resident_key,
requireResidentKey: resident_key == :required,
rp: %{
id: challenge.rp_id,
name: app_name
Expand Down
2 changes: 2 additions & 0 deletions priv/static/registration_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const RegistrationHook = {
attestation,
challenge,
excludeCredentials,
residentKey,
requireResidentKey,
rp,
timeout,
Expand All @@ -29,6 +30,7 @@ export const RegistrationHook = {
attestation,
authenticatorSelection: {
authenticatorAttachment: "platform",
residentKey: residentKey,
requireResidentKey: requireResidentKey,
},
challenge: challengeArray.buffer,
Expand Down

0 comments on commit 38a1253

Please sign in to comment.