liveshowy / webauthn_components

WebauthnComponents allows Phoenix developers to quickly add passwordless authentication to LiveView applications.
MIT License
178 stars 10 forks source link

Accept User Details #45

Closed type1fool closed 1 year ago

type1fool commented 1 year ago

Overview

Resolves #44

This PR allows the parent LiveView to send user details (id, name, displayName) used by the WebAuthn API. The name is displayed to the user during registration and authentication, and the changes here will allow multiple users to share the same device.

The parent LiveView will be responsible for determining what appears as the name and display name. Some apps will choose email, others will choose usernames, for example.

Changes

image

Tests

mix test

22:00:46.533 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.344.0>}

22:00:46.533 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.343.0>}

22:00:46.533 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.354.0>}

22:00:46.533 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.349.0>}

22:00:46.535 [debug] Replied in 4ms

22:00:46.535 [debug] Replied in 4ms

22:00:46.535 [debug] Replied in 4ms

22:00:46.535 [debug] Replied in 4ms

22:00:46.536 [debug] HANDLE EVENT
  Component: WebauthnComponents.TokenComponent
  View: LiveIsolatedComponent.View
  Event: "error"
  Parameters: %{"message" => "test message", "name" => "test name", "stack" => %{}}

22:00:46.536 [debug] Replied in 33µs
.
22:00:46.536 [debug] HANDLE EVENT
  Component: WebauthnComponents.RegistrationComponent
  View: LiveIsolatedComponent.View
  Event: "invalid"
  Parameters: %{"invalid_key" => "invalid value"}

22:00:46.536 [debug] Replied in 17µs
.
22:00:46.537 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.370.0>}

22:00:46.537 [debug] Replied in 31µs

22:00:46.537 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.374.0>}

22:00:46.537 [debug] Replied in 91µs

22:00:46.537 [debug] HANDLE EVENT
  Component: WebauthnComponents.SupportComponent
  View: LiveIsolatedComponent.View
  Event: "passkeys-supported"
  Parameters: %{"supported" => true}

22:00:46.537 [debug] Replied in 44µs

22:00:46.538 [debug] HANDLE EVENT
  Component: WebauthnComponents.AuthenticationComponent
  View: LiveIsolatedComponent.View
  Event: "authenticate"
  Parameters: %{}
...
22:00:46.539 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.383.0>}

22:00:46.539 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.387.0>}

22:00:46.539 [debug] Replied in 51µs

22:00:46.539 [debug] Replied in 51µs

22:00:46.539 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.381.0>}

22:00:46.539 [debug] Replied in 36µs

22:00:46.539 [debug] HANDLE EVENT
  Component: WebauthnComponents.SupportComponent
  View: LiveIsolatedComponent.View
  Event: "invalid"
  Parameters: %{"invalid_key" => "invalid value"}

22:00:46.539 [debug] Replied in 20µs

22:00:46.539 [debug] HANDLE EVENT
  Component: WebauthnComponents.TokenComponent
  View: LiveIsolatedComponent.View
  Event: "invalid"
  Parameters: %{"invalid_key" => "invalid value"}

22:00:46.539 [debug] Replied in 24µs
...
22:00:46.540 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.397.0>}

22:00:46.540 [debug] Replied in 34µs

22:00:46.540 [debug] Replied in 1ms

22:00:46.540 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.399.0>}

22:00:46.540 [debug] Replied in 53µs
..
22:00:46.540 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.407.0>}

22:00:46.540 [debug] Replied in 42µs

22:00:46.540 [debug] HANDLE EVENT
  Component: WebauthnComponents.TokenComponent
  View: LiveIsolatedComponent.View
  Event: "token-exists"
  Parameters: %{"token" => "1234"}

22:00:46.540 [debug] Replied in 15µs
.
22:00:46.541 [debug] HANDLE EVENT
  Component: WebauthnComponents.RegistrationComponent
  View: LiveIsolatedComponent.View
  Event: "register"
  Parameters: %{}

22:00:46.541 [debug] Replied in 61µs

22:00:46.541 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.414.0>}

22:00:46.541 [debug] Replied in 60µs
.
22:00:46.541 [debug] HANDLE EVENT
  Component: WebauthnComponents.TokenComponent
  View: LiveIsolatedComponent.View
  Event: "token-cleared"
  Parameters: %{"token" => nil}

22:00:46.541 [debug] Replied in 38µs
.
22:00:46.541 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.419.0>}

22:00:46.541 [debug] Replied in 36µs

22:00:46.541 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.423.0>}

22:00:46.541 [debug] Replied in 27µs

22:00:46.542 [debug] HANDLE EVENT
  Component: WebauthnComponents.TokenComponent
  View: LiveIsolatedComponent.View
  Event: "token-stored"
  Parameters: %{"token" => "123456"}

22:00:46.542 [debug] Replied in 21µs

22:00:46.542 [debug] HANDLE EVENT
  Component: WebauthnComponents.RegistrationComponent
  View: LiveIsolatedComponent.View
  Event: "error"
  Parameters: %{"message" => "test message", "name" => "test name", "stack" => %{}}

22:00:46.542 [debug] Replied in 20µs
..
22:00:46.542 [debug] MOUNT LiveIsolatedComponent.View
  Parameters: :not_mounted_at_router
  Session: %{"live_isolated_component_store_agent" => #PID<0.431.0>}

22:00:46.542 [debug] Replied in 39µs

22:00:46.543 [debug] HANDLE EVENT
  Component: WebauthnComponents.RegistrationComponent
  View: LiveIsolatedComponent.View
  Event: "registration-attestation"
  Parameters: %{"attestation64" => "cNEYi+IEPP+wsZzGH5Nw29fDo6TJwjkW3/8NCB/XZTKENSn5eZPAEaIWNDhU6H74vDWgfTIhgsxTk494hlLS9A", "clientData" => [], "rawId64" => "Gz2w0GkHBfKByC+F50hkdxVPC5QgohgnefEOKIBU4oMc3vpmGIBFR35h84nShF83GvXfeDdX4+NxrSXimuQjsA", "type" => "public-key"}

22:00:46.548 [debug] Replied in 5ms
.
Finished in 0.1 seconds (0.1s async, 0.00s sync)
16 tests, 0 failures

Randomized with seed 419416

Collaborators

  1. @type1fool