Permalink
Browse files

Fix #2 issue

  • Loading branch information...
1 parent 0281d98 commit 14ca86fc34bd5548f239bdb5b5e4ee79a69ad169 @KirillTemnov committed Apr 19, 2011
Showing with 26 additions and 24 deletions.
  1. +23 −22 lib/server.js
  2. +1 −1 lib/util.js
  3. +2 −1 package.json
View
@@ -28,9 +28,9 @@ function getRequestToken(query, store, fn) {
function invalidUrl (res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('Url invalid');
- res.end();
+ res.setHeader('Content-Type', 'text/plain');
+ res.statusCode = 404
+ res.end("url invalid");
}
/**
@@ -60,19 +60,19 @@ var OAuthServer = function (domain, actions, protectedActions, port, store) {
// todo
// check timestamp and nonce
// create access token and sent it to consumer
- res.writeHead(302, { Location: rt.consumer.callbackUrl +
+ res.setHeader("Location",rt.consumer.callbackUrl +
'?oauth_token=' + rt.key +
- '&oauth_verifier='+
- rt.verifier + ''});
+ '&oauth_verifier=' + rt.verifier);
+ res.statusCode = 302;
res.end();
}
else {
// todo
// deny access
// remove request token
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('Access from ' + rt.consumer.name + ' declined');
- res.end();
+ res.setHeader('Content-Type', 'text/plain');
+ res.statusCode = 404;
+ res.end('Access from ' + rt.consumer.name + ' declined');
}
}
else {
@@ -97,16 +97,17 @@ var OAuthServer = function (domain, actions, protectedActions, port, store) {
if (! error) {
var token = generateRequestToken(params, consumer);
store.addRequestToken(token);
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('oauth_token='+ token.key + '&oauth_token_secret=' +
+ res.setHeader('Content-Type', 'text/plain');
+ res.end('oauth_token='+ token.key + '&oauth_token_secret=' +
token.secret+ '&oauth_callback_confirmed=true');
// additional params
}
else {
- res.writeHead(404, {'Content-Type': 'text/plain'});
+ res.setHeader('Content-Type', 'text/plain')
console.log(error);
+ res.statusCode = 404;
+ res.end();
}
- res.end();
});
}
// else { missing authorization
@@ -125,15 +126,15 @@ var OAuthServer = function (domain, actions, protectedActions, port, store) {
var accessToken = generateAccessToken(requestToken);
store.addAccessToken(accessToken);
store.removeRequestToken(requestToken);
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.write('oauth_token=' + accessToken.key +
+ res.setHeader('Content-Type', 'text/plain');
+ res.end('oauth_token=' + accessToken.key +
'&oauth_token_secret=' + accessToken.secret);
}
else {
- res.writeHead(404, {'Content-Type': 'text/plain'});
- res.write(error);
+ res.setHeader('Content-Type', 'text/plain');
+ res.statusCode = 404;
+ res.end(error);
}
- res.end();
});
});
}
@@ -147,7 +148,7 @@ var OAuthServer = function (domain, actions, protectedActions, port, store) {
var query = qs.parse((URL.parse(req.url)).query);
getRequestToken(query, store, function (rt) {
if (rt) {
- res.writeHead(200, {'Content-Type': 'text/html'});
+ res.setHeader('Content-Type','text/html')
var data =
'<html> <head> <title> OAuth server test page </title> </head>' +
'<body><h1>Allow ' + rt.consumer.name + ' application ? </h1>'+
@@ -162,11 +163,11 @@ var OAuthServer = function (domain, actions, protectedActions, port, store) {
'</body></html>';
- res.write(data);
- res.end();
+ res.end(data);
}
else {
- res.writeHead(403, {'Content-Type': 'text/plain'});
+ res.setHeader('Content-Type', 'text/plain')
+ res.statusCode = 403;
res.end('goes wrong');
}
});
View
@@ -136,7 +136,7 @@ exports.checkAccess = function(req, store, fn) {
var generateKeypair = function(generatorKey, string, algorithm) {
algorithm = algorithm || 'sha256';
- var key = crypto.createHmac('sha1', generatorKey).update(new Date()).digest('base64')
+ var key = crypto.createHmac('sha1', generatorKey).update(Date.now().toString()).digest('base64')
.replace(/\=/g, '.').replace(/\//g, '-').replace(/\+/g, '_');
var secret = crypto.createHmac(algorithm, key).update(string).digest('base64')
.replace(/\=/g, '.').replace(/\//g, '-').replace(/\+/g, '_');
View
@@ -1,8 +1,9 @@
{ "name": "oauth-server",
"description": "Server, supporting OAuth version 1.0A",
- "version": "0.1.5",
+ "version": "0.2.0",
"main": "main",
"engines": ["node >= 0.3.1"],
"author": "Temnov Kirill <allselead@gmail.com>",
+ "dependencies": { "connect": ">= 1.0", "oauth": "*" },
"repository": {"type": "git", "url": "http://github.com/selead/oauth-server.git"}
}

0 comments on commit 14ca86f

Please sign in to comment.