GithubHelp home page GithubHelp logo

berrysauce / passkey-demo Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 253 KB

๐Ÿ”‘ WebAuthn Passkey Server Demo

Home Page: https://passkeys.berrysauce.me

License: MIT License

TypeScript 23.73% HTML 76.27%
honojs passkeys passkeys-demo webauthn webauthn-demo cloudflare worker

passkey-demo's Introduction

Passkey Demo Icon
Passkey Server Demo

This is a demo login using Passkeys. Passkeys are not new, but they've gained a lot of popularity recently as big tech companies like Apple and Google have implemented them in their products. This demo simulates the registration and authentication of a user using passkeys. The server and client (user's browser) use the Passwordless.ID WebAuthn implementation. Thanks to them for making such an easy-to-use library!

Warning: I cannot guarantee your data's security. This is just a demo. The data stored on the server is just from your site-specific passkey โ€“ which shouldn't be a problem, even if an attacker gets to it. Use it at your own risk. You shouldn't use this in production.

Stack

Cloudflare Worker JWT (a very cool library!) is used for the server-side JWT implementation. I also recommend taking a look at HonoJS. It's a small but powerful router which works with Cloudflare Workers. There's still some work to do with the documentation, but that's ok, as it's quite fresh. It's really great and easy to use.

How it works

The Passwordless.ID repository has a very nice graphic for how the WebAuthn process works. I'll just copy it here:

Graphic explaining the WebAuthn process

Source: Passwordless.ID WebAuthn Repository

Development

First, clone the repo to your machine and install all dependencies. Then, run the local development server. Some features might not work in local development mode.

Note: It seems like the WebAuthn spec requires valid SSL certificates. Currently, local development mode doesn't work. I recommend using wrangler tail to get the live logs from your active Cloudflare Worker instance for debugging.

npm install
npm run dev

You also need to create a file called .dev.vars in the project directory with the following content:

JWT_TOKEN=<RANDOM TOKEN HERE FOR JWT SIGNING>

Additionally, you need to pass the JWT_TOKEN onto your active Worker instance via wrangler (more on that here).

Now, create a wrangler.toml file (or edit your existing one) to match the following:

name = "passkey-demo"
main = "src/index.ts"
compatibility_date = "2023-01-01"
kv_namespaces = [
  { binding = "DB", id = "YOUR_KV_ID", preview_id = "YOUR_PREVIEW_KV_ID" }
]

[site]
bucket = "./static"

Deploy your passkey application as a Cloudflare Worker via wrangler with the following command.

npm run deploy

passkey-demo's People

Contributors

berrysauce avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

sumanadak

passkey-demo's Issues

does not work locally or when deployed to cloudflare

This is a nice start to a demo, but the login with passkeys button either spins when deploying locally, or cannot authenticate when deployed to cloudflare with a custom domain.

I suspect that the calls to encryption need domain specific settings, but haven't researched the code yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.