miguel's notebooks

  • Untitled - /miguel/oauth-test
    Last edited 7 years ago
    var express = require('express'), bodyParser = require('body-parser'), oauthserver = require('oauth2-server'); var app = express(); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.oauth = oauthserver({ model: {}, // See below for specification grants: ['password'], debug: true }); app.all('/oauth/token', app.oauth.grant()); app.get('/', app.oauth.authorise(), function (req, res) { res.send('Secret area'); }); app.use(app.oauth.errorHandler()); app.listen(3000); function tonicExpress(anExport) { var mount = express(); // "mount" is our root app, and it mounts "app" at your notebook path // which is available in the TONIC_MOUNT_PATH environment variable mount.use(process.env.TONIC_MOUNT_PATH || "", app); if (anExport) { anExport.tonicEndpoint = mount; } // overwrite .listen since it is not needed app.listen = function(){} // return the express instance for use by the caller return app; } module.exports = tonicExpress