Skip to content

Instantly share code, notes, and snippets.

@robertpitt
Created July 5, 2012 03:33
Show Gist options
  • Save robertpitt/3051063 to your computer and use it in GitHub Desktop.
Save robertpitt/3051063 to your computer and use it in GitHub Desktop.
Sampel of Oauth flow
/**
* Oauth 2.0 basic example
*/
var express = require('express');
var oauth = require('oauth-server');
/**
* Create a new server
*/
var server = module.exports = express.createServer();
/**
* Configure the server
*/
server.configure(function(){
/**
* Configure the oauth
*/
server.use(oauth.middleware({
db : "mongodb://localhost/oauth",
expiresIn : 3600,
supportedScopes : [
'profile',
'status',
'avatar'
]
}));
/**
* Router must be used after OAuth
*/
server.use(server.router);
});
server.get("/api/@me", function(req, res, next){
/**
* Assure that the access-token is valid
*/
req.validateAccessToken(req, res, function(){
/**
* Anything inside of this function is authorized
*/
res.send({succes : true});
});
})
/**
* Listen on port 8124
*/
server.listen(8124, function(){
console.log("Server listening on port %d in %s mode", server.address().port, server.settings.env);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment