-
Notifications
You must be signed in to change notification settings - Fork 14
Populate allowCredentials for authenticators without residential keys #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
defmodule WebauthnComponents.RegistrationComponent do | ||
@moduledoc """ | ||
A LiveComponent for registering a new Passkey via the WebAuthn API. | ||
A LiveComponent for registering a new Passkey via the WebAuthn API! | ||
|
||
> Registration = Sign Up | ||
|
||
|
@@ -123,8 +123,8 @@ defmodule WebauthnComponents.RegistrationComponent do | |
title="Create a new account" | ||
disabled={@disabled} | ||
> | ||
<span :if={@show_icon?} class="w-4 aspect-square opacity-70"><.icon_key /></span> | ||
<span><%= @display_text %></span> | ||
<span :if={@show_icon?} class="aspect-square w-4 opacity-70"><.icon_key /></span> | ||
<span>{@display_text}</span> | ||
Comment on lines
+126
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These changes should be omitted since they're not related to the goals of the PR. It may still be too early to convert to the new brackets syntax ( |
||
</.button> | ||
</span> | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
defmodule WebauthnComponents.WebauthnCredential do | ||
@moduledoc """ | ||
Struct representing a credential to be used by the WebAuthn API. | ||
""" | ||
|
||
@enforce_keys [:id, :public_key] | ||
defstruct [:id, :public_key] | ||
|
||
@type t :: %__MODULE__{ | ||
id: binary(), | ||
public_key: String.t() | ||
} | ||
|
||
defimpl Jason.Encoder, for: __MODULE__ do | ||
def encode(struct, opts) do | ||
map = Map.from_struct(struct) | ||
|
||
encoded_public_key = | ||
for {k, v} <- map[:public_key], into: %{} do | ||
if is_binary(v) do | ||
{k, Base.encode64(v)} | ||
else | ||
{k, v} | ||
end | ||
end | ||
|
||
encoded_map = %{id: Base.encode64(map[:id]), public_key: encoded_public_key} | ||
Jason.Encode.map(encoded_map, opts) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,15 @@ export const AuthenticationHook = { | |
|
||
async handlePasskeyAuthentication(event, context, mediation) { | ||
try { | ||
const { challenge, timeout, rpId, allowCredentials, userVerification } = | ||
const { challenge, timeout, rpId, allowCredentialsIDs, userVerification } = | ||
event; | ||
|
||
// allowCredentialsIDs is an array of already base64 encoded IDs | ||
allowCredentials = new Array(); | ||
for (const id of allowCredentialsIDs) { | ||
allowCredentials.push({ id: base64ToArray(id), type: 'public-key' }); | ||
}; | ||
|
||
const challengeArray = base64ToArray(challenge); | ||
|
||
const publicKey = { | ||
|
@@ -55,6 +61,9 @@ export const AuthenticationHook = { | |
timeout, | ||
userVerification, | ||
}; | ||
|
||
console.log(publicKey); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This console log should be removed. |
||
|
||
const credential = await navigator.credentials.get({ | ||
publicKey, | ||
signal: AbortControllerService.createNewAbortSignal(), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,8 @@ export const RegistrationHook = { | |
const publicKey = { | ||
attestation, | ||
authenticatorSelection: { | ||
authenticatorAttachment: "platform", | ||
// authenticatorAttachment: "platform", | ||
authenticatorAttachment: "all", | ||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears https://www.w3.org/TR/webauthn-3/#enumdef-authenticatorattachment In fact, I could not find Ultimately, the plan is to make all of these parameters configurable from the Elixir code instead of hardcoding things in JS. That's out of scope for this branch, but worth noting. |
||
residentKey: residentKey, | ||
requireResidentKey: requireResidentKey, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be omitted.