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

passport-yubico

v1.0.1

Published

Yubikey authentication strategy for Passport.

Downloads

12

Readme

#Passport-Yubico

A Yubico provider for the passport authentication library.

Features

The Yubikey authentication facility returns a serial number for the Yubikey device, and a generated identity value. The values can be used alone to identify and authenticate a user (i.e. instead of a user identifier and password); or can be used alongside a username OR password to make a fairly secure, but minimal impact authentication system; or can be used with a username AND password to make a highly secure web site.


To Install

npm install passport-yubico

You require an API Key and client ID from Yubico:

https://upgrade.yubico.com/getapikey/


To Use

The Yubikey needs a single input field:

<input type="text" name="yubikey">

The name of the field is also configurable (yubicoPasswordField) in the options:

var __options__ = {

	yubicoAPIKey: '{your API Key}',

	yubicoClientId: '{your client ID}',

	usernameField: 'username',

	passwordField: 'password',

	yubicoPasswordField: 'yubikey',

	passReqToCallback: true
};

To use the passport plugin, you add the following entry:

YubicoStrategy = require('passport-yubico').Strategy;

passport.use('yubico', new YubicoStrategy(__options__, 

	function(req, username, password, serial, identity, done) {

		/* 
		 * Get your user, and confirm password if required
		 * 
		 * Then check the users Yubikey...
		 *
		 */

		if(user.yubicoKeys[serial] === identity){

			done(user, null);

		} else {

			done(null, 'Not confirmed');
		}

	}

));

In the above example, we have a user record that has an additional information for the users Yubikey(s), below is an example of this user record as a JSON object...

{
	id: '1234567890',

	username: 'testuser',

	password: 'testpassword',

	yubicoKeys:{

		'1234567': 'ccabfedddeaccdfabbe'

	},

	firstName: 'Joe',

	lastName: 'Bloggs'
}

###The last piece of the Jigsaw... Or should that be the first? Before you can check the Yubikeys credentials, you need to be able to retrieve them from the Yubico servers and store them somewhere for later verification, for this there is a Utility module within the passport-yubico library. To use this.....

var YubicoUtility = require('passport-yubico').Utility;

var yubicoUtility = new YubicoUtility({

	yubicoAPIKey: '{your API Key}',

	yubicoClientId: '{your client ID}',
});

yubicoUtility.getCredentials({yubikey password from form}, function(err, data) {

	if (!err && data) {

		console.log('Serial: ' + data.serial);

		console.log('Identity: ' + data.identity);

		/*
		 * This is where you would store the credentials to the users record e.g.:
		 *
		 * user.yubicoKeys = user.yubicoKeys || {};
		 *
		 * user.yubicoKeys[data.serial] = data.identity
		 *
		 */

	} else if (err) {

		console.error('Lookup returned Error: ' + err);

	} else {

		console.error('No data returned');

	}

	return next(err);
});

This functionality is typically placed on the users account page that allows the user to add a Yubico key as part of their authentication process.


#Want to say thank you? A bit coin donation is always welcome ;-)

1HPaCHrbZtrvoVoEdH1mFqqY5jwVHcXVK3