All Projects → strangerlabs → Webauthn

strangerlabs / Webauthn

Licence: mit
W3C Web Authentication API Relying Party for Node.js and Express

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Webauthn

Mean Angular5 Passport Authentication
Securing MEAN Stack (Angular 5) Web Application using Passport Authentication
Stars: ✭ 24 (-60.66%)
Mutual labels:  express, expressjs, authentication
Mern Stack Authentication
Secure MERN Stack CRUD Web Application using Passport.js Authentication
Stars: ✭ 60 (-1.64%)
Mutual labels:  express, expressjs, authentication
Express Jwt
An example API for creating/verifying json web tokens
Stars: ✭ 105 (+72.13%)
Mutual labels:  express, expressjs, authentication
Express Openapi Validator
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
Stars: ✭ 436 (+614.75%)
Mutual labels:  express, expressjs, express-middleware
Naperg
Fullstack Boilerplate GraphQL. Made with React & Prisma + authentication & roles
Stars: ✭ 661 (+983.61%)
Mutual labels:  expressjs, authentication
Openuserjs.org
The home of FOSS user scripts.
Stars: ✭ 632 (+936.07%)
Mutual labels:  express, expressjs
Rest Api Nodejs Mongodb
A boilerplate for REST API Development with Node.js, Express, and MongoDB
Stars: ✭ 672 (+1001.64%)
Mutual labels:  express, expressjs
Opine
Fast, minimalist web framework for Deno ported from ExpressJS.
Stars: ✭ 506 (+729.51%)
Mutual labels:  express, expressjs
Pretzel
Javascript full-stack framework for Big Data visualisation and analysis
Stars: ✭ 26 (-57.38%)
Mutual labels:  express, expressjs
Webpack2 Express Heroku Starter
Starter app using Webpack 2, Express, setup to deploy to Heroku.
Stars: ✭ 12 (-80.33%)
Mutual labels:  express, expressjs
Mean Angular4 Chat App
MEAN stack with Angular 4 Chat App
Stars: ✭ 41 (-32.79%)
Mutual labels:  express, expressjs
Express Babel
Express starter kit with ES2017+ support, testing, linting, and code coverage
Stars: ✭ 621 (+918.03%)
Mutual labels:  express, expressjs
Express Validator
An express.js middleware for validator.js.
Stars: ✭ 5,236 (+8483.61%)
Mutual labels:  express, expressjs
Jebena
Lightweight JSON validation library
Stars: ✭ 56 (-8.2%)
Mutual labels:  express, express-middleware
Generator Express No Stress
🚂 A Yeoman generator for Express.js based 12-factor apps and apis
Stars: ✭ 534 (+775.41%)
Mutual labels:  express, expressjs
Node Iframe Replacement
An alternative to sticking that lovely web app you just built into an <iframe> on a corp website
Stars: ✭ 37 (-39.34%)
Mutual labels:  expressjs, express-middleware
Gitwar
🚀 Gitwar - Compete with Github
Stars: ✭ 44 (-27.87%)
Mutual labels:  express, expressjs
Celebrate
A joi validation middleware for Express.
Stars: ✭ 1,041 (+1606.56%)
Mutual labels:  express, express-middleware
Passport Magic Login
Passwordless authentication with magic links for Passport.js.
Stars: ✭ 493 (+708.2%)
Mutual labels:  express, authentication
Node Production
Take Your Node.js Project to The Production Environment (VPS/Dedicated Server).
Stars: ✭ 35 (-42.62%)
Mutual labels:  express, expressjs

WebAuthn

standard-readme compliant build-status codecov

W3C Web Authentication API Relying Party for Node.js and Express

WebAuthn is a W3C standard that enables web developers to replace passwords in their applications with FIDO authentication. This repository implements a NPM package for use in Node.js services. This package is in active development and not yet ready for production use. You can use it to kick the tires on WebAuthn. Please file issues to ask questions or provide feedback.

Table of Contents

Security

This package is not yet ready for use in production software. For more information on security considerations see W3C Web Authentication and FIDO Security Reference.

Install

$ npm install webauthn

Usage

See examples for a complete example. The package currently works on its own and we plan to support Passport.js integration in future releases.

const WebAuthn = require('webauthn')

// configure express and session middleware; see "examples" in this repository
// ...

// Create webauthn
const webauthn = new WebAuthn({
  origin: 'http://localhost:3000',
  usernameField: 'username',
  userFields: {
    username: 'username',
    name: 'displayName',
  },
  store: new LevelAdapter(),
  // OR
  // store: {
  //   put: async (id, value) => {/* return <void> */},
  //   get: async (id) => {/* return User */},
  //   search: async (search) => {/* return { [username]: User } */},
  //   delete: async (id) => {/* return boolean */},
  // },
  rpName: 'Stranger Labs, Inc.',
  enableLogging: false,
})

// Mount webauthn endpoints
app.use('/webauthn', webauthn.initialize())

// Endpoint without passport
app.get('/secret', webauthn.authenticate(), (req, res) => {
  res.status(200).json({ status: 'ok', message: 'Super Secret!' })
})

Client

import Client from 'webauthn/client'

const client = new Client({ pathPrefix: '/webauthn' })

await client.register({
  username: 'AL1C3',
  name: 'Alice',
})

// ...

await client.login({ username: 'AL1C3' })

API

Relying Party

new WebAuthn(options)

The main entrypoint for creating a new WebAuthn RP instance. options is used to configure the behaviour of the RP. Available options include:

  • origin - The origin of the deployed application.
  • rpName - The display name of RP. This will be shown in the WebAuthn consent interface.
  • [usernameField = 'name'] - The name of the field that uniquely identifies a user.
  • [userFields = ['name', 'displayName'] ] - One of:
    • An array of properties from registration request to be included in the saved user object
    • An object mapping, where the key is the name of a property from the registration request to be included in the user object and the value is the name of that property on the user object.
  • [store = MemoryAdapter] - The storage interface for user objects. Defaults to an object in memory (for testing only).
  • [attestation = 'none'] - the attestation conveyance preference. Setting this to anything other than 'none' will require attestation and validate it.
  • [credentialEndpoint = '/register'] - the path of the credential attestation challenge endpoint.
  • [assertionEndpoint = '/login'] - the path of the challenge assertion endpoint.
  • [challengeEndpoint = '/response'] - the path of the challenge response endpoint.
  • [logoutEndpoint = '/logout'] - the path of the logout endpoint.
  • [enableLogging = true] - Enable or disable logging to stdout.

webauthn.initialize()

Returns an Express Router with the mounted WebAuthn endpoints.

webauthn.authenticate([options])

Returns an Express Middleware that will set req.user for subsequent middlewares, or produce a 401 Unauthorized error if the user is not authenticated. Available options include:

  • [failureRedirect] - If the user fails to authenticate then they will be redirected to the supplied URL.

Storage Adapater

Storage adapters provide an interface to the WebAuthn RP to store and retrieve data necessary for authentication, such as authenticator public keys. Storage adapters must implement the following interface:

async get (id)

Retrieves and returns the previously stored object with the provided id.

async put (id, value)

Stores an object so that it may be retrieved with the provided id. Returns nothing.

async search (startsWith, [options])

Returns a mapping of objects where the id of the objects return starts with the provided query value. Available options include:

  • limit: Return the first N results.
  • reverse: Return results in reverse lexicographical order. If used in conjunction with limit then the last N results are returned.

async delete (id)

Delete a previously stored object. Returns a boolean indicating success.

Browser Client

new Client([options])

Constructs a new client for handling interaction with the Web Authentication API and the server authentication endpoints. Available options include:

  • [pathPrefix = '/webauthn'] - A mounting prefix to all authorization endpoints.
  • [credentialEndpoint = '/register'] - The path of the credential registration endpoint.
  • [assertionEndpoint = '/login'] - The path of the challenge assertion endpoint.
  • [challengeEndpoint = '/response'] - The path of the challenge response endpoint.
  • [logoutEndpoint = '/logout'] - The path of the logout endpoint.

Returns a new client instance.

async client.register(data)

Completes a start-to-finish registration of a new authenticator at the remote service with the following steps:

  1. Fetch a register credential challenge from the remote server's credentialEndpoint.
  2. Prompt the Credentials Management API to generate a new local credential.
    • The Credentials Management API prompts the user for consent.
    • The challenge is signed using the user-selected method and returned.
  3. The signed challenge is returned to the remote server's challengeEndpoint.

Returns the response of the request to the challengeEndpoint.

async client.login(data)

Completes a start-to-finish assertion challenge on a previously registered remote service with the following steps:

  1. Fetch an assertion challenge from the remote server's assertionEndpoint.
  2. Prompt the Credentials Management API to get an existing local credential and sign the response.
    • The Credentials Management API prompts the user for consent.
    • The challenge is signed and returned.
  3. The signed challenge is returned to the remote server's challengeEndpoint.

Returns the response of the request to the challengeEndpoint.

async client.logout()

Destroys the current session on the remote server. Returns the result of the request to the logoutEndpoint.

Maintainers

@Terrahop

@EternalDeiwos

@christiansmith

Originally adapted from fidoalliance/webauthn-demo.

Contributing

Issues

  • Please file issues :)
  • When writing a bug report, include relevant details such as platform, version, relevant data, and stack traces
  • Ensure to check for existing issues before opening new ones
  • Read the documentation before asking questions
  • It is strongly recommended to open an issue before hacking and submitting a PR

Pull requests

Policy

  • We're not presently accepting unsolicited pull requests
  • Create an issue to discuss proposed features before submitting a pull request
  • Create an issue to propose changes of code style or introduce new tooling
  • Ensure your work is harmonious with the overall direction of the project
  • Ensure your work does not duplicate existing effort
  • Keep the scope compact; avoid PRs with more than one feature or fix
  • Code review with maintainers is required before any merging of pull requests
  • New code must respect the style guide and overall architecture of the project
  • Be prepared to defend your work

Style guide

Code reviews

  • required before merging PRs
  • reviewers MUST run and test the code under review

Tests

Run the test suite with npm test.

Code of conduct

License

MIT © 2019 Stranger Labs, Inc.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].