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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mlhacks/passport-mlh-oauth2

v4.0.1

Published

MyMLH v4 OAuth 2.0 authentication strategy for Passport

Readme

passport-mlh-oauth2

npm version Build Status

This is the official Passport.js strategy for authenticating with MyMLH in Node.js applications. To use it, you'll need to register an application and obtain an OAuth Application ID and Secret from MyMLH.

It now supports MyMLH API V4. Read the MyMLH V4 docs here.

Requirements

This module requires Node.js version 14.0.0 or higher.

Installation

Install the package via npm:

npm install @mlhacks/passport-mlh-oauth2

Usage

Configure Strategy

You can find a list of potential scopes and expandable fields in the MyMLH API documentation. The defaults below are provided simply as an example.

const passport = require('passport');
const MLHStrategy = require('passport-mlh-oauth2');

passport.use(new MLHStrategy({
    clientID: process.env.MY_MLH_KEY,
    clientSecret: process.env.MY_MLH_SECRET,
    callbackURL: 'https://www.example.net/auth/mlh/callback',
    scope: 'public offline_access user:read:profile',
    expandFields: ['education']
  },
  function(accessToken, refreshToken, profile, cb) {
    // In this callback, you can process the profile data and decide what to do with it.
    // For example, you might save the user to your database.
    User.findOrCreate({ mlhId: profile.id }, function (err, user) {
      return cb(err, user);
    });
  }
));

Authenticate Requests

Use passport.authenticate() middleware to authenticate requests.

app.get('/auth/mlh',
  passport.authenticate('mlh'));

app.get('/auth/mlh/callback', 
  passport.authenticate('mlh', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication, redirect home.
    res.redirect('/');
  });

Accessing User Data

After successful authentication, the profile object returned by the strategy contains the user's MyMLH profile information. The profile has the following properties:

  • provider - always set to mlh
  • id - the user's MyMLH ID
  • first_name - the user's first name
  • last_name - the user's last name
  • email - the user's email address
  • Other fields as per the scopes and expand fields you have requested.

Example:

app.get('/auth/mlh/callback', 
  passport.authenticate('mlh', { failureRedirect: '/login' }),
  function(req, res) {
    // Successful authentication
    console.log(req.user);
    res.redirect('/');
  });

You can access user information in your route handlers using req.user.

app.get('/profile', ensureAuthenticated, function(req, res){
  const user = req.user;
  const firstName = user.first_name;
  res.render('profile', { user: user });
});

You can find the full User object structure in the MyMLH API documentation.

Options

  • clientID - Your MyMLH application's client ID.
  • clientSecret - Your MyMLH application's client secret.
  • callbackURL - URL to which MyMLH will redirect the user after granting authorization.
  • authorizationURL - OAuth authorization endpoint (defaults to https://www.mlh.com/oauth/authorize).
  • tokenURL - OAuth token endpoint (defaults to https://api.mlh.com/v4/oauth/token).
  • scope - Space-separated list of permissions (e.g., 'public offline_access user:read:profile').
  • expandFields - Optional array of fields to expand in the user profile (e.g., ['education', 'professional_experience']).

Questions?

Have a question about the API or this library? Start by checking out the official MyMLH documentation. If you still can't find an answer, tweet at @MLHacks or drop an email to [email protected].