Added Basic HTTP Authorization support #32

Closed
wants to merge 2 commits into
from
View
4 app.js
@@ -478,6 +478,10 @@ function processRequest(req, res, next) {
options.path += apiConfig.keyParam + '=' + apiKey;
}
+ if (apiConfig.auth=='basicAuth') {
+ options.headers['Authorization']='Basic '+new Buffer(reqQuery.apiUsername+':'+reqQuery.apiPassword).toString('base64');
+ }
+
// Perform signature routine, if any.
if (apiConfig.signature) {
if (apiConfig.signature.type == 'signed_md5') {
@@ -173,9 +173,11 @@
var params = $(this).serializeArray(),
apiKey = { name: 'apiKey', value: $('input[name=key]').val() },
apiSecret = { name: 'apiSecret', value: $('input[name=secret]').val() },
- apiName = { name: 'apiName', value: $('input[name=apiName]').val() };
+ apiName = { name: 'apiName', value: $('input[name=apiName]').val() },
+ apiUsername = { name: 'apiUsername', value: $('input[name=username]').val() },
+ apiPassword = { name: 'apiPassword', value: $('input[name=password]').val() };
- params.push(apiKey, apiSecret, apiName);
+ params.push(apiKey, apiSecret, apiName, apiUsername, apiPassword);
// Setup results container
var resultContainer = $('.result', self);
View
@@ -14,30 +14,40 @@ form#credentials
img(src='/images/accept.png')
- else
h2 API Credentials
- img(src='/images/key.png')
+ img(src='/images/key.png')
- - if (apiInfo.oauth)
- input(type='hidden', name='oauth', value='authrequired')
-
- - if (apiInfo.auth.defaultKey)
- - var defaultKey =apiInfo.auth.defaultKey
- - else
- - var defaultKey =''
-
- - if (apiInfo.auth.defaultSecret)
- - var defaultSecret =apiInfo.auth.defaultSecret
+ - if(apiInfo.auth == 'basicAuth')
+ div (basic HTTP authorization)
+ br
+ div
+ label(for='key') User name
+ input(id='username', name='username', style='color=#EEEEEE')
+ div
+ label(for='key') Password
+ input(id='password', name='password', value=defaultKey, style='color=#EEEEEE')
- else
- - var defaultSecret =''
- div
- label(for='key') API Key
- input(id='key', name='key', value=defaultKey, style='color=#EEEEEE')
- div
- - if (apiInfo.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.oauth)
+ input(type='hidden', name='oauth', value='authrequired')
+
+ - if (apiInfo.auth.defaultKey)
+ - var defaultKey =apiInfo.auth.defaultKey
+ - else
+ - var defaultKey =''
+
+ - if (apiInfo.auth.defaultSecret)
+ - var defaultSecret =apiInfo.auth.defaultSecret
+ - else
+ - var defaultSecret =''
+ div
+ label(for='key') API Key
+ input(id='key', name='key', value=defaultKey, style='color=#EEEEEE')
div
- input(name='oauth', value='Authenticate with OAuth', type='submit', id='oauth-auth')
+ - if (apiInfo.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')
+ div
+ input(name='oauth', value='Authenticate with OAuth', type='submit', id='oauth-auth')
div(id='controls')
ul