Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #7 from tresbailey/master

Passes travis. Merging
  • Loading branch information...
commit 26566c54b9005153122a0cfa26decbd0a0ed3304 2 parents cfaa49b + 8e85985
Ryan Fairchild authored November 08, 2012
5  Readme.md
Source Rendered
@@ -33,7 +33,8 @@ Sending requests works very similar to the latest version of node's built-in htt
33 33
 		path: '/1/statuses/update.json',
34 34
 		oauth_signature: signer,
35 35
 		method: 'POST',
36  
-		body: body
  36
+		body: body,
  37
+        realm: 'my_realm'
37 38
 	}
38 39
 	
39 40
 	request = oauth.request(request, function(response) { ... });
@@ -117,4 +118,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
117 118
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
118 119
 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
119 120
 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
120  
-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  121
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10  lib/oauth.js
@@ -116,7 +116,7 @@ exports.request = function(options, callback) {
116 116
 		'content-type': 'application/x-www-form-urlencoded',
117 117
 		'host': options.host,
118 118
 		'accept': '*/*',
119  
-		'www-authenticate': 'OAuth realm=' + (options.https ? 'https' : 'http') + '://' + options.host
  119
+		'www-authenticate': 'OAuth realm=' + (options.realm ? options.realm : ((options.https ? 'https' : 'http') + '://' + options.host))
120 120
 	};
121 121
 
122 122
 	if(!options.headers) {
@@ -128,7 +128,7 @@ exports.request = function(options, callback) {
128 128
 
129 129
 	var uri = exports.fillURL(options.path, options.host, options.port, options.https);
130 130
 	options.headers = signRequest(options.method, uri, options.headers, 
131  
-		options.body, options.oauth_signature);
  131
+		options.body, options.oauth_signature, options.realm);
132 132
 
133 133
 	var req;
134 134
 	if (options.https) {
@@ -144,11 +144,12 @@ exports.request = function(options, callback) {
144 144
 		
145 145
 		return http.ClientRequest.prototype.write.call(this, chunk, 'utf-8');
146 146
 	};
147  
-
  147
+    
  148
+    req.end();
148 149
 	return req;
149 150
 };
150 151
 
151  
-function signRequest(method, path, headers, body, signature) {
  152
+function signRequest(method, path, headers, body, signature, realm) {
152 153
 	var auth = {
153 154
 		'oauth_nonce': nonce(),
154 155
 		'oauth_timestamp': timestamp(),
@@ -194,6 +195,7 @@ function signRequest(method, path, headers, body, signature) {
194 195
 	
195 196
 	var esc = querystring.escape;
196 197
 	querystring.escape = _encodeURI;
  198
+    auth.realm = realm;
197 199
 	auth = querystring.stringify(exports.normalize(auth), '\",', '=\"');
198 200
 	querystring.escape = esc;
199 201
 
33  test/test_realm_signature.js
... ...
@@ -0,0 +1,33 @@
  1
+var vows = require('vows'),
  2
+    assert = require('assert'),
  3
+    oauth = require('../lib/oauth'),
  4
+	uuid = require('node-uuid');
  5
+
  6
+vows.describe('RealmSignatures') .addBatch({
  7
+  'In a valid request token flow': {
  8
+    topic: function() {
  9
+      var hmac = oauth.createHmac(consumer,token);
  10
+      var consumer = oauth.createConsumer( 'sign_key', 'sign_secret' );
  11
+      var token = null;
  12
+      var signed = oauth.createHmac( consumer, token );
  13
+      var method = 'post',
  14
+          url = 'http://api.google.com/oauth',
  15
+          realm = 'testable_realm',
  16
+          params = {
  17
+            oauth_signature_method:'HMAC-SHA1',
  18
+            oauth_version:'1.0'
  19
+          };
  20
+      return oauth.signRequest(method, url, {}, {}, signed, realm);
  21
+    },
  22
+    'Auth header should be set to ': function(topic) {
  23
+
  24
+    var oauth_pattern = /OAuth oauth_consumer_key\=\"sign_key\"\,oauth_nonce\=\"[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\"\,oauth_signature_method\=\"HMAC-SHA1\"\,oauth_timestamp\=\"[0-9]{10}\"\,oauth_version\=\"1\.0\"\,realm\=\"testable_realm\"\,oauth_signature\=/g;
  25
+
  26
+    var matched = oauth_pattern.exec(topic.authorization);
  27
+    if ( assert.isArray( matched ) ) {
  28
+        return assert.isNotEmpty( matched );
  29
+    }
  30
+    return false;
  31
+    }
  32
+  }
  33
+}).export(module);

0 notes on commit 26566c5

Please sign in to comment.
Something went wrong with that request. Please try again.