在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);