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

express-facebook-auth

v1.0.1

Published

A wrapper for express that simplifies some of the boilerplate for using Facebook for authentication

Downloads

6

Readme

Express Facebook Auth

Opinionated Node.js authentication middleware for express that uses Facebook. By being opinionated, this module is relatively straightforward to use, as far as authentication is concerned. In all honestly, I mostly created this module because I was getting tired of copy-pasting the same code over and over :-P

Installation

npm install express-facebook-auth

Example usage

Let's start by creating a login page for our users called login.pug. This example uses the Pug templating engine.

doctype html
body
  a(href='https://www.facebook.com/v2.10/dialog/oauth?client_id=' + facebookAppId + '&redirect_uri=' + redirectUri) Login with Facebook

Then, we create our express app:

const { Authenticator } = require('express-facebook-auth');
const express = require('express');
const cookieParser = require('cookie-parser');

const app = express();
app.set('view engine', 'pug');

// Cookie parser is Needed by express-facebook-auth to pass the Facebook
// authentication token from the browser to this server
app.use(cookieParser());

// The login URI is used to specify the endpoint, relative to the `app` property
// passed to `authenticator.createLoginSuccessEndpoint` method
const loginUri = '/login';

// The redirect URI must be a fully qualified domain name, as this is passed to
// Facebook from the browser, which it then uses to redirect the browser on its own
const redirectUri = 'http://myserver.net/login-success/';

const authenticator = new Authenticator({
  facebookAppId: process.env.FACEBOOK_APP_ID,
  facebookAppSecret: process.env.FACEBOOK_APP_SECRET,

  // This callback is used to determine if the given Facebook user is allowed to
  // access your system. By the time this method is called, the user has already
  // been authenticated against Facebook. For this example, let's just say all
  // Facebook users are registered with this server. In practice, you should have
  // this method query your own user database to associate the Facebook ID with your user
  isUserRegistered: (facebookId) => true,
  loginUri,
  redirectUri
});

// Render the login.pug file from above when a user navigates to http://myserver.net/login
app.get(loginUri, (req, res) => {
  res.render('login', {
    facebookAppId: process.env.FACEBOOK_APP_ID,
    redirectUri
  });
});

authenticator.createLoginSuccessEndpoint(app);

// The boolean value passed to createMiddleware indicates whether or not a failed
// login attempt should redirect back to `loginUri`, or return a 401 HTTP code. A
// good rule of thumb is to set this to `true` for page URLs, and `false` for API
// calls (i.e. XHR or Fetch calls)
app.get('/', authenticator.createMiddleware(true), (req, res) => {
  res.send('If you can see this, you are logged in!');
});

app.listen(3000, () => console.log('Example authenticated app listening on port 3000!'));

License

MIT License

Copyright (c) 2018 Bryan Hughes [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.