Giter Site home page Giter Site logo

andbang-express-auth's Introduction

And Bang auth middleware for Express.js

World's simplest OAuth.

  1. Sign up for an And Bang account at https://andbang.com

  2. Register your application at https://accounts.andbang.com/developer

    When setting your redirect URL, make sure your path is /auth/andbang/callback. For example: localhost:9000/auth/andbang/callback

  3. Copy your app's client ID and secret, and insert them into the middleware's constructor, like in the example below.

  4. Add a link or button that points to /auth somewhere on your page. You can also optionally set the "next" url to go to after successful auth all in one swoop by doing /auth?next={{some URL}}.

  5. ...

  6. Profit!

The code below should work once you've dropped in your client ID and secret:

var express = require('express'),
    andbangAuth = require('andbang-express-auth'),
    app = express();

// config our middleware
app.use(express.cookieParser());
app.use(express.session({ secret: 'keyboard cat' }));
app.use(andbangAuth.middleware({
    app: app,
    clientId: '<< YOUR CLIENT ID>>',
    clientSecret: '<< YOUR CLIENT SECRET>>',
    defaultRedirect: '/secured'
}));

// Just re-direct people to '/auth' and the plugin does the rest.
app.get('/', function (req, res) {
    res.send('<a href="/auth">login</a>');
});

// For routes where you want to require login,
// add the middleware like this:
app.get('/secured', andbangAuth.secure(), function (req, res) {
    res.send(req.session.user);
});

License

MIT

andbang-express-auth's People

Contributors

henrikjoreteg avatar legastero avatar nlf avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.