Permalink
Browse files

adding a rather hacky set of oauth2 support - requires an access toke…

…n is already fetched
  • Loading branch information...
1 parent 1f4a828 commit 2a29b22cc92fe7aac116006d2f8f2e7536eee8f4 @lornajane committed Sep 25, 2012
Showing with 19 additions and 9 deletions.
  1. +11 −5 app.js
  2. +8 −4 views/api.jade
View
16 app.js
@@ -125,7 +125,7 @@ function oauth(req, res, next) {
var apiName = req.body.apiName,
apiConfig = apisConfig[apiName];
- if (apiConfig.oauth) {
+ if (apiConfig.auth == "oauth") {
var apiKey = req.body.apiKey || req.body.key,
apiSecret = req.body.apiSecret || req.body.secret,
refererURL = url.parse(req.headers.referer),
@@ -476,8 +476,8 @@ function processRequest(req, res, next) {
options.path += ((paramString.length > 0) ? '?' + paramString : "");
}
- // Add API Key to params, if any.
- if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
+ // Add API Key to params, if any (except if it's OAuth2)
+ if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined && apiConfig.auth != "oauth2") {
if (options.path.indexOf('?') !== -1) {
options.path += '&';
}
@@ -522,6 +522,10 @@ function processRequest(req, res, next) {
options.headers = headers;
}
+ if (apiConfig.auth == 'oauth2' && req.body.oauth == 'authrequired') {
+ options.headers['Authorization'] = "OAuth " + req.body.apiKey;
+ }
+
if (!options.headers['Content-Length']) {
if (requestBody) {
options.headers['Content-Length'] = requestBody.length;
@@ -699,6 +703,8 @@ app.get('/:api([^\.]+)', function(req, res) {
if (!module.parent) {
var port = process.env.PORT || config.port;
- app.listen(port);
- console.log("Express server listening on port %d", app.address().port);
+ var l = app.listen(port);
+ l.on('listening', function(err) {
+ console.log("Express server listening on port %d", app.address().port);
+ });
}
View
@@ -29,13 +29,17 @@ form#credentials
- else
- var defaultSecret =''
div
- label(for='key') API Key
- input(id='key', name='key', value=defaultKey, style='color=#EEEEEE')
+ - if (apiInfo.auth == 'oauth2')
+ label(for='key') Access Token (yes, cheating)
+ input(id='key', name='key', style='color=#EEEEEE')
+ - else
+ label(for='key') API Key
+ input(id='key', name='key', value=defaultKey, style='color=#EEEEEE')
div
- - if (apiInfo.oauth || apiInfo.signature)
+ - if (apiInfo.auth == 'oauth' || apiInfo.signature)
label(for='secret') Shared Secret
input(id='secret', name='secret', value=defaultSecret, style='color=#EEEEEE')
- - if (apiInfo.oauth && apiInfo.oauth.type !='two-legged')
+ - if (apiInfo.auth == 'oauth' && apiInfo.oauth && apiInfo.oauth.type !='two-legged')
div
input(name='oauth', value='Authenticate with OAuth', type='submit', id='oauth-auth')

0 comments on commit 2a29b22

Please sign in to comment.