Implementing WebAuthn via LiveView

It’s not publicly available yet, but I intend to extract it from the app and release a package.

3 Likes

Update

I will be speaking at ElixirConf 2022 on this topic, and I plan to release a new Hex package, WebAuthnLiveComponent. :tada:

The package is a work in progress, and I have most of the Phoenix code in place. Since WebAuthn is a browser API, I have added a JS hook named WebAuthn, which is used by the component’s HTML form.

Call for Help

In order to release this as a package, I need to bundle the JS with the Elixir code. I haven’t found clear instructions for doing this in the Hex or Mix docs. I’ve referenced the source code in phoenix_live_view and react-phoenix, but it’s not clear exactly what I need to do for a LiveComponent with a JS hook.

So, I’m looking for help getting the JS module into the Hex package, assuming this can/should be done. If publishing to NPM isn’t necessary, I’d like to avoid it.

5 Likes

Neither of those are directly involved, other than making sure your package.json file winds up in the Hex package along with the desired JS. For instance, here’s the config from phoenix_html:

The other half of the setup is in the generated esbuild config in any Phoenix app:

Setting NODE_PATH to ../deps means that any Hex package in deps that also quacks like an Node package (ie, has a package.json) will work. For instance, that’s how you can say import "phoenix_html" in app.js.

3 Likes

Thank you, Matt! :beers: The phoenix_html example was very helpful. The only other hurdle was that I had been using the component via a local path instead of GitHub or Hex, so the JS wasn’t being pulled in. Now that I’m using the (currently private) Hex package, everything is in its right place :musical_note:.

1 Like

This is awesome.

I was frantically searching for a Fido implementation, because I want to make use of Passkeys after updating my Mac & related devices, but I may not be able to implement it from scratch like you did!!

Perhaps you can add a demo like this:

Thank You.

2 Likes

Hey @derpycoder! At ElixirConf, I released an early alpha WebAuthnLiveComponent on Hex. It’s not ready for production, but you can find more details in the forum thread dedicated to the new package. Now that LiveView 0.18 is out, I am planning to update the component, add tests and docs, and get it ready for beta testing before the end of the year.

3 Likes