npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

auth0-mfa-flow

v1.0.4

Published

Auth0 Multi-factor Authentication

Downloads

371

Readme

auth0-mfa-flow

Used in conjunction with https://github.com/auth0/auth0.js
If you have multi-factor authentication enabled auth0-js will lead to a dead-end.
Use this library to continue the auhtentication process.
This library only favours mfa via sms, voice or other otp delivery at this point.

Usage

import auth0 from 'auth0-js';
import Auth0MFAFlow, {mfaDefaultOptions} from 'auth0-mfa-flow';

const clientId = 'YOUR_AUTH0_APPLICATION_CLIENT_ID';
const domain = 'YOUR_AUTH0_APPLICATION_DOMAIN';

const auth = new auth0.Authentication({
  doamin,
  clientID: clientId,
  scope: 'openid profile email',
  responseType: 'code'
});

// mfaDefaultOptions
// Auth0MFAFLow default config is for oob type with just sms channel
// see https://auth0.com/docs/api/authentication#multi-factor-authentication 
// for more details and otp type
const options = {
	challengeType: 'oob', // or 'otp'
	oobChannels: ['sms'],
	authenticatorTypes: ['oob'], // or ['otp']
	grantType: 'http://auth0.com/oauth/grant-type/mfa-oob'
};

const mfaAuth = new Auth0MFAFLow(clientId, domain); // add options as a 3rd parameter

const startMultiFactorAuth = (mfaToken) => {
	// SHOW MOBILE NUMBER INPUT FIELD
	const mobileNumber = 'GET_THE_USER_MOBILE_NUMBER'; // OPTIONAL for oob ( Required if sms or voice )
	// get the mobile number from the user if required
	const {error} = mfaAuth.start(mfaToken, mobileNumber);
	if (!error) {
		// SHOW OTP INPUT FIELD
		// to resend the OTP call mfaAuth.challenge()
		// once user enters OTP and submits form, call onOtpSubmit
	} else {
		// SHOW ERROR MESSAGE
	}
};

const onOtpSubmit = async (otp) => {
	const {data} = await mfaAuth.complete(otp);
	if (data) {
		// data contains your access_token
		auth.userInfo(data.access_token, async (error, profile) => {
		
		});
	} else {
		// SHOW ERROR MESSAGE
	}
};

auth.login(
	{
		realm: 'Username-Password-Authentication',
		username: 'AUTH0_USER_USERNAME_FROM_USER_INPUT',
		password: 'AUTH0_USER_PASSWORD_FROM_USER_INPUT'
	},
	async (err, authResult) => {
		if (err || !authResult) {
			if (err) {
				const {code, original} = err;
				if (code === 'mfa_required') {
					// with multi-factor enabled
					const {
						response: {
							body: {mfa_token}
						}
					} = original;
					startMultiFactorAuth(mfa_token);
				}
			}
		} else {
			// without multi-factor enabled
			auth.userInfo(authResult.accessToken, async (error, profile) => {
		
			});
		}
	}
);