0.0.3 • Published 9 years ago

koa-grant-type v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

koa-grant-type

Simple router based on grant_type of request.

NOTE

This branch is for koa v2, which uses Promises instead of Generator functions.

Installation

npm install koa-grant-type --save

Usage

const Koa = require('koa');
const bodyparser = require('koa-bodyparser');
const route = require('koa-route');
const GrantType = require('koa-grant-type');

const app = new Koa();
app.use(bodyparser());

const grantHandlers = new GrantType();

grantHandlers.use((ctx, next) => {
  ctx.assert(ctx.request.body.client_id, 400);
  ctx.assert(ctx.request.body.client_secret, 400);
  return next();
});

grantHandlers.grant('refresh_token', (ctx, next) => {
  ctx.assert(ctx.request.body.refresh_token, 400);
  return next();
}, (ctx) => {
  // Generate new token
  ctx.body = token;
});

app.use(route.post('/token', grantHandlers.routes()));
0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago