Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sdd/koa-seneca-auth-middleware
https://github.com/sdd/koa-seneca-auth-middleware
Last synced: 15 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/sdd/koa-seneca-auth-middleware
- Owner: sdd
- Created: 2015-05-29T11:39:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T11:47:21.000Z (about 1 year ago)
- Last Synced: 2024-10-31T00:08:50.259Z (2 months ago)
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# koa-seneca-auth-middleware
```
var _ = require('lodash'),
Promise = require('bluebird'),
seneca = Promise.promisifyAll(require('seneca')()),
Router = require('koa-router');
module.exports = function(options) {
const defaults = {
auth_url: '/auth/:strategy',
callback_url: '/auth/:strategy/callback'
};
var scriptResponse = "try{window.opener.postMessage('token');}catch(e){};window.close();";
options = _.extend(defaults, options);
const router = new Router();
router.get(options.auth_url, function* () {
var params = ['request_token', 'verify_token'];
var authArgs = _.pick(this.req.query, params);
authArgs.auth = 'authenticate';
authResponse = yield seneca.act(authArgs);
this.body = authResponse;
});
router.get(options.callback_url, function* () {
var params = ['request_token', 'verify_token'];
var authArgs = _.pick(this.req.query, params);
authArgs.auth = 'authenticate';
authResponse = yield seneca.act(authArgs);
this.body = scriptResponse;
});
return router.middleware();
};
```