Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added realm to all calls if specified (not just echo) #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/oauth.js
Expand Up @@ -6,7 +6,7 @@ var crypto= require('crypto'),
querystring= require('querystring'), querystring= require('querystring'),
OAuthUtils= require('./_utils'); OAuthUtils= require('./_utils');


exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize, customHeaders) { exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, version, authorize_callback, signatureMethod, nonceSize, customHeaders, realm) {
this._isEcho = false; this._isEcho = false;


this._requestUrl= requestUrl; this._requestUrl= requestUrl;
Expand All @@ -28,6 +28,7 @@ exports.OAuth= function(requestUrl, accessUrl, consumerKey, consumerSecret, vers
this._headers= customHeaders || {"Accept" : "*/*", this._headers= customHeaders || {"Accept" : "*/*",
"Connection" : "close", "Connection" : "close",
"User-Agent" : "Node authentication"} "User-Agent" : "Node authentication"}
this._realm= realm;
this._clientOptions= this._defaultClientOptions= {"requestTokenHttpMethod": "POST", this._clientOptions= this._defaultClientOptions= {"requestTokenHttpMethod": "POST",
"accessTokenHttpMethod": "POST"}; "accessTokenHttpMethod": "POST"};
this._oauthParameterSeperator = ","; this._oauthParameterSeperator = ",";
Expand Down Expand Up @@ -112,7 +113,7 @@ exports.OAuth.prototype._isParameterNameAnOAuthParameter= function(parameter) {
// build the OAuth request authorization header // build the OAuth request authorization header
exports.OAuth.prototype._buildAuthorizationHeaders= function(orderedParameters) { exports.OAuth.prototype._buildAuthorizationHeaders= function(orderedParameters) {
var authHeader="OAuth "; var authHeader="OAuth ";
if( this._isEcho ) { if( this._realm ) {
authHeader += 'realm="' + this._realm + '",'; authHeader += 'realm="' + this._realm + '",';
} }


Expand Down
12 changes: 12 additions & 0 deletions tests/oauth.js
Expand Up @@ -267,6 +267,18 @@ vows.describe('OAuth').addBatch({
Array.prototype.toString = _toString; Array.prototype.toString = _toString;
} }
}, },
'When building the OAuth Authorization header with a realm': {
topic: new OAuth(null, null, null, null, null, null, "HMAC-SHA1", null, null, 'http://foobar.com/'),
'The realm should be prepended correctly' : function(oa) {
var parameters= [
["oauth_timestamp", "1234567"],
["oauth_nonce", "ABCDEF"],
["oauth_version", "1.0"],
["oauth_signature_method", "HMAC-SHA1"],
["oauth_consumer_key", "asdasdnm2321b3"]];
assert.equal(oa._buildAuthorizationHeaders(parameters), 'OAuth realm="http://foobar.com/",oauth_timestamp="1234567",oauth_nonce="ABCDEF",oauth_version="1.0",oauth_signature_method="HMAC-SHA1",oauth_consumer_key="asdasdnm2321b3"');
}
},
'When performing the Secure Request' : { 'When performing the Secure Request' : {
topic: new OAuth("http://foo.com/RequestToken", topic: new OAuth("http://foo.com/RequestToken",
"http://foo.com/AccessToken", "http://foo.com/AccessToken",
Expand Down