Permalink
Browse files

Generate proper OAuth token

  • Loading branch information...
1 parent d854000 commit 561d6678db2d2eec01ddd789a79378b6b9f9bf43 @galfert galfert committed Feb 22, 2012
Showing with 16 additions and 4 deletions.
  1. +13 −1 lib/express-storage.js
  2. +3 −3 server.js
View
@@ -142,11 +142,23 @@ exports.storage = (function() {
});
}
+ function generateToken() {
+ var tokenLength = 32;
+ var charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ var token = "";
+
+ for(var i=0; i < tokenLength; i++)
+ token += charSet.charAt(Math.floor(Math.random() * charSet.length));
+
+ return token;
+ }
+
return {
addToken: addToken,
removeToken: removeToken,
addUser: addUser,
createToken: createToken,
- doReq: doReq
+ doReq: doReq,
+ generateToken: generateToken
};
})();
View
@@ -14,12 +14,12 @@ var app = module.exports = express.createServer();
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
- app.set('view options', {layout: false});
+ app.set('view options', {layout: false});
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
- app.use('/', express.errorHandler({ dump: true, stack: true }));
+ app.use('/', express.errorHandler({ dump: true, stack: true }));
});
app.configure('development', function(){
@@ -66,7 +66,7 @@ app.get('/_oauth/:user', function(req, res){
});
app.post(/^\/_oauth\/(?:(.+))/, function(req, res){
- var token = "yo-ho"; //TODO generate proper token
+ var token = storage.generateToken();
storage.createToken(req.param('userId'), req.param('password'), token, req.param('scope'), function(result) {
if(result) {

0 comments on commit 561d667

Please sign in to comment.