Skip to content

Instantly share code, notes, and snippets.

@robwormald
Created December 19, 2013 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwormald/8047424 to your computer and use it in GitHub Desktop.
Save robwormald/8047424 to your computer and use it in GitHub Desktop.
config__slash__passport.js
ar passport = require('passport'),
oauth2orize = require('oauth2orize'),
jwtBearer = require('oauth2orize-jwt-bearer').Exchange,
login = require('connect-ensure-login'),
utils = require('../innitUtils.js');
module.exports = {
express: {
customMiddleware: function(app)
{
/** oAuth Server **/
app.use(passport.initialize());
app.use(passport.session());
var server = oauth2orize.createServer();
// Register supported grant types.
//
// OAuth 2.0 specifies a framework that allows users to grant client
// applications limited access to their protected resources. It does this
// through a process of the user granting access, and the client exchanging
// the grant for an access token.
// Grant authorization codes. The callback takes the `client` requesting
// authorization, the `redirectURI` (which is used as a verifier in the
// subsequent exchange), the authenticated `user` granting access, and
// their response, which contains approved scope, duration, etc. as parsed by
// the application. The application issues a code, which is bound to these
// values, and will be exchanged for an access token.
server.grant(oauth2orize.grant.code(function(client, redirectURI, user, ares, done) {
var code = utils.uid(16);
Authcode.create({
code: code,
client: client.id,
redirectURI: redirectURI,
user: user.id,
scope: ares.scope
}).done(function(err,code){
if(err){return done(err,null);}
return done(null,code.code);
});
}));
...etc//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment