koajs

Koa OAuth服务

node.js里用于实现OAuth2服务器/提供者与koa完整,标准,以及测试模块

koa包装于: https://github.com/thomseddon/node-oauth2-server

安装

$ npm install koa-oauth-server

入门

该模块提供了一个单一的中间件:

var koa = require('koa');
var oauthserver = require('koa-oauth-server');

var app = koa();

app.oauth = oauthserver({
  model: {}, // 查看https://github.com/thomseddon/node-oauth2-server for specification
  grants: ['password'],
  debug: true
});

app.use(app.oauth.authorise());

app.use(function *(next) {
  this.body = 'Secret area';
  yield next;
});

app.listen(3000);