authmaker-verify-express
Express middlewares for authmaker-verify
Last updated 2 years ago by real_ate .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install authmaker-verify-express 
SYNC missed versions from official npm registry.

Build Status Code Climate

Version npm Dependencies npm Downloads

Authmaker Verify Express

This package allows you to use Authmaker verify extremely easily in an ExpressJS based Node application.

Installation

npm install --save authmaker-verify-express

Usage

This package currently makes use of the Mongo connection for Authmaker Verify so you need to initialise the database connection before use:

var authmakerVerify = require('authmaker-verify');
authmakerVerify.connectMongo(nconf);

You need to pass a nconf object into the connectMongo call that has access to at least the following parameters:

{
    "mongo": {
        "authmaker": {
            "db": "your-db-name",
            "host": "localhost",
            "port": 27017
        }
    }
}

you can also optionally include username and password. Each of these config entries are accessed asynchronously so you can use any of the asynchronous stores for nconf

Middlewares

To actually use this package you just need to include middlewares in your ExpressJS app. Here are a few examples of ways you can use authmaker-verify-express. Please note that all of these examples use a simple "success" callback that does nothing but responds with a 200 response code. They have also already imported required modules:

var authmakerVerifyExpress = require('authmaker-verify-express');
var express = require('express');
var app = express();

function success(req, res){
    return res.send("Success");
}

Requires users with valid, in date access tokens in the request:

app.get('/verify': [authmakerVerifyExpress.mongo(), success]);

Requires users with valid, in date access tokens with the scope "my_awesome_permission":

app.get('/scope': [authmakerVerifyExpress.mongo("my_awesome_permission"), success]);

Requires users with valid, in date access tokens with a rate limited scope (suffix _limit_<num>_<timeframe>)

app.get('/jointrated': [authmakerVerifyExpress.mongoRateLimited("face"), success]);

Requires users with valid, in date access token but if they don't have a rate limited scope it uses face_limit_10_minutes as a default scope:

app.get('/defaultScope': [authmakerVerifyExpress.mongoRateLimited("face", "face_limit_10_minutes"), success]);

API

mongoRateLimited - function - returns middleware

mongoRateLimited: function(tag, defaultScope)

mongoRateLimitedDefault - function - returns middleware

mongoRateLimitedDefault: function(tag, defaultScope)

mongo - function - returns middleware

mongo: function(tag, options)

options.passError (optional) if true passes error via middleware

connectMongo - function

connectMongo: function(nconf) {
    //initialise the db
    authmakerVerify.connectMongo(nconf);
}

authmakerVerify - object

If you ever need to access the authmaker-verify object that is powering authmaker-verify-express to access any lower level apis you can access it directly like this:

var authmakerVerifyExpress = require('authmaker-verify-express');
authmakerVerifyExpress.authmakerVerify;

Current Tags

  • 3.0.2                                ...           latest (a year ago)

16 Versions

  • 3.0.2                                ...           a year ago
  • 3.0.1                                ...           2 years ago
  • 2.3.0                                ...           2 years ago
  • 3.0.0                                ...           2 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.2.1                                ...           4 years ago
  • 1.2.0                                ...           4 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (6)
Dev Dependencies (10)

Copyright 2014 - 2016 © taobao.org |