Coder Social home page Coder Social logo

Authn-Id Project

This library allows you to easily add multi-factor authentication (MFA) or passwordless signin to your web application.

  • You can simply add an email verification
  • You can simply add MFA using fingerprint, Face ID or PIN powered by WebAuthn

Read the Authn.id documentation

Installation

Frontend

npm install @authn-id/browser
import AuthnId from "@authn-id/browser";

Backend

const apiUrl = "https://api.authn.id/v1";

Email Verification

You can verify an email for multi-factor authentication, user registration or passwordless login.

email_verification

1. Send a verification link (frontend)

const authnId = new AuthnId.Client({ apiKey: API_KEY });

const email = "[email protected]";
const { approved, token } = await authnId.verifyEmail(email);

if (approved) {
  const response = await fetch(`/your-backend/verifyEmail?token=${token}`);
  const verified = await response.json();
  if (verified.success) {
    // Success!
  }
}

2. Verify a token (backend)

const { token } = req.query;

const response = await fetch(apiUrl + "/verify/token", {
  method: "POST",
  body: token,
  headers: { "x-authnid-api-secret": API_SECRET, "Content-Type": "text/plain" },
});

var result = await response.json();
if (result.success) {
  // Success!
}

WebAuthn (Passkeys)

You can verify a user with platform authenticator for MFA or passwordless signin.

  • Windows: Fingerprint, Facial recognition or PIN (Windows Hello)
  • Mac & iOS: Touch ID or Face ID
  • Android: fingerprint, face or screen lock

Registration

webauthn_registration

1. Retrieve a registration token (backend)

const body = {
  userId: "1234567",
  username: "[email protected]",
  displayName: "John Doe",
};

const response = await fetch(apiUrl + "/register/authenticator", {
  method: "POST",
  body: JSON.stringify(body),
  headers: {
    "x-authnid-api-secret": API_SECRET,
    "Content-Type": "application/json",
  },
});

const token = await response.text();

2. Initiate the registration (frontend)

const authnId = new AuthnId.Client({ apiKey: API_KEY });

const response = await fetch("/your-backend/registerAuthenticator");
const token = await response.text();

try {
  await authnId.registerAuthenticator(token);
  // Success!
} catch (e) {
  // Error
}

Authentication

webauthn_authentication

1. Start the authentication (frontend)

const authnId = new AuthnId.Client({ apiKey: API_KEY });

const username = "[email protected]";
const token = await authnId.authenticate(username);

const response = await fetch(`/your-backend/verifyUser?token=${token}`);
const authenticated = await response.json();
if (authenticated.success) {
  // Success!
}

2. Verify the token (backend)

const { token } = req.query;

const response = await fetch(apiUrl + "/verify/token", {
  method: "POST",
  body: token,
  headers: { "x-authnid-api-secret": API_SECRET, "Content-Type": "text/plain" },
});

var result = await response.json();
if (result.success) {
  // Success!
}

SigninID's Projects

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.