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

github-auth

v3.0.2

Published

connect compatible middleware for auth with github

Downloads

32

Readme

github-auth npm version Dependency Status

A middleware for github authentication.

Installation

You can install this module with npm

npm install github-auth

Usage

You can use the middleware on a connect/express app like this.

var githubAuth = require('github-auth');

var config = {
	team: 'some-team',
	organization: 'my-company',
	autologin: true, // This automatically redirects you to github to login.
	hideAuthInternals: true // After authentication this redirects to original url but without query parameters 'code' and 'state'.
};
var gh = githubAuth('github app id', 'github app secret', config);
app.use(gh.authenticate);

That will validate that the user belongs to the 'some-team' team of the 'my-company' organization on github.

You can also use a whitelist of users, like this.

var githubAuth = require('github-auth');

var config = {
	users: ['sorribas', 'mafintosh', 'octocat']
};
var gh = githubAuth('github app id', 'github app secret', config);
app.use(gh.authenticate);

The authenticate middleware sets the req.github property to an object which contains user and authenticated. That way you can decide what to do with unauthenticated users (redeirect them to the login page for example). If the req.github object is not present it means that the user has not tried to login, so you should redirect them to the github login page which is on gh.loginUrl

You can also use the .login middleware which redirects you to the github oauth login page.

app.get('ghlohin', gh.login);

To get the users in a team with the github API you need the full write access on the user profile, which is not really nice. You can avoid this by passing some github credentials with access to the team to the module so it uses basic HTTP auth.

var githubAuth = require('github-auth');

var config = {
	team: 'some-team',
	organization: 'my-company',
	credentials: {
		user: 'myghuser',
		pass: 'mypass'
	}
};
app.use(githubAuth('github app id', 'github app secret', config).authenticate);

Also, you don't have to use this module with connect or express. You could just use it in your regular node http server like this.


http.createServer(function(request, response) {
	var config = {
		team: 'some-team',
		organization: 'my-company'
	};
	githubAuth('github app id', 'github app secret', config).authenticate(request, response, function(err) {
		if (err) return response.end(err);

		// your http code here
	});
});

Configuration

  • maxAge: Sets the maxAge of the authentication cookie (milliseconds). Defaults to set a session cookie.
  • secret: The module uses a random secret to sign the authentication cookie. If you want to manage this yourself you can do it by providing it as part of the config.

Examples

There is an example in the examples folder using Express 3. To run it you need to install express 3.x and github-auth.