1.0.10 • Published 4 years ago

@frenatix/webauthn-js v1.0.10

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

webauthn-js: A webauthn server lib for node.js

Motivation

When I was looking for a server implementation of webauthn in JS, I stumpled over an webauthn example app made by the Microsoft Edge team. In contrast to other server implementations in JS it worked straight away with my FIDO2 authenticators. So I decided to extract the code and build a server lib.

Installation

npm i @frenatix/webauthn-js

Usage

const webauthn = require('@frenatix/webauth-js')

API

registerNewCredential()

const authenticatorData = await webauthn.registerNewCredential({
  response: {
    // from authenticator
    id: 'BBOD...',
    clientDataJSON: '{"type":"webauthn.create","challenge":"123","origin":"http://localhost:3001",":false}',
    attestationObject: 'o2NmbXRmcG...'
  },
  getValidChallengeToken: async (challenge) => {
    const challengeToken = //...
    return challengeToken
  },
  expectedHostname: 'localhost',
  isValidCredentialId: async (credentialId) => {
    /*...*/
  },
  saveUserCredential: async ({ id, publicKeyJwk, signCount, challengeToken }) => {
    /*...*/
  }
})

Parameters

NameTypeDescription
responseObjectThe response of the authenticator (described here). It consists of the properties clientDataJSON and attestationObject
getValidChallengeTokenfunction(challenge)Should returns true if challenge check was successful
userVerificationstringrequired | preferred | discouraged, default. preferred
expectedHostnamestring | functionThe hostname for this credential
isValidCredentialIdfunction(credentialId)Check if the credential is already used
saveUserCredentialfunction({id, publicKeyJwk, signCount, challengeToken})Callback function when credential creation was created

verifyAssertion()

verifyAssertion({
  assertion: { 
    // from authenticator
    id: 'WICPLj...',
    clientDataJSON: '{"type":"webauthn.get","challenge":"123","origin":"http://localhost:3001","crossOrigin":false}',
    signature: 'MEUCIQD...',
    authenticatorData: 'SZYN5...',
  },
  credential: {
    // from storage
    id: 'AB123..',
    publicKeyJwk: {
      kty: 'EC',
      crv: 'P-256',
      x: 'MSNo3...',
      y: 'm9sY...'
    },
    signCount: 2
  },
  getValidChallengeToken: async (challenge) => {
    const challengeToken = //...
    return challengeToken
  },
  expectedHostname: 'localhost',
  isAllowedCredentialId: (credentialId) => true,
  updateSignCount: async ({ credentialId, oldSignCount, newSignCount }) => {
    /*...*/
  }
})

Parameters

NameTypeDescription
assertionObjectThe response of the authenticator (described here)
getValidChallengeTokenfunction(challenge)Should returns true if challenge check was successful
userVerificationstringrequired | preferred | discouraged, default. preferred
expectedHostnamestring | functionThe hostname for this credential
isAllowedCredentialIdfunction(credentialId)Check if the credential is already allowed
updateSignCountfunction({credentialId, oldSignCount, newSignCount})Callback function to update the sign count

Demo Project

You can find a demo project how to use this lib here.

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago