Created
January 11, 2011 04:30
-
-
Save bitdrift/774019 to your computer and use it in GitHub Desktop.
Patch for node-openid. Allows use in Node.js v0.2.x.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e498b243d2ce8eea58ae8d7278bba41cb4476dad Mon Sep 17 00:00:00 2001 | |
From: Ryan Probasco <ryan@bitdrift.org> | |
Date: Mon, 10 Jan 2011 21:13:00 -0700 | |
Subject: [PATCH 1/2] Make query string param retrieval compatible with v0.2.x | |
--- | |
openid.js | 35 +++++++++++++++++++++++------------ | |
1 files changed, 23 insertions(+), 12 deletions(-) | |
diff --git a/openid.js b/openid.js | |
index 8ec811c..b4155c9 100644 | |
--- a/openid.js | |
+++ b/openid.js | |
@@ -732,7 +732,7 @@ openid.verifyAssertion = function(requestOrUrl) | |
return { authenticated: false, error: 'Provider signature is invalid or expired' }; | |
} | |
- return { authenticated : true , identifier: assertionUrl.query['openid.claimed_identifier'] }; | |
+ return { authenticated : true , identifier: _param(assertionUrl.query, 'openid.claimed_identifier') }; | |
} | |
function _getAssertionError(params) | |
@@ -741,11 +741,11 @@ function _getAssertionError(params) | |
{ | |
return 'Assertion request is malformed'; | |
} | |
- else if(params['openid.mode'] == 'error') | |
+ else if(_param(params, 'openid.mode') == 'error') | |
{ | |
- return params['openid.error']; | |
+ return _param(params, 'openid.error'); | |
} | |
- else if(params['openid.mode'] == 'cancel') | |
+ else if(_param(params, 'openid.mode') == 'cancel') | |
{ | |
return 'Authentication cancelled'; | |
} | |
@@ -755,29 +755,29 @@ function _getAssertionError(params) | |
function _checkValidHandle(params) | |
{ | |
- return !_isDef(params['openid.invalidate_handle']); | |
+ return !_isDef(_param(params, 'openid.invalidate_handle')); | |
} | |
function _checkSignature(params) | |
{ | |
- if(!_isDef(params['openid.signed']) || | |
- !_isDef(params['openid.sig'])) | |
+ if(!_isDef(_param(params, 'openid.signed')) || | |
+ !_isDef(_param(params, 'openid.sig'))) | |
{ | |
return false; | |
} | |
- var association = openid.loadAssociation(params['openid.assoc_handle']); | |
+ var association = openid.loadAssociation(_param(params, 'openid.assoc_handle')); | |
if(association.expiry_time < new Date().getTime()) | |
{ | |
return false; | |
} | |
var message = ''; | |
- var signedParams = params['openid.signed'].split(','); | |
+ var signedParams = _param(params, 'openid.signed').split(','); | |
for(var index in signedParams) | |
{ | |
var param = signedParams[index]; | |
- var value = params['openid.' + param]; | |
+ var value = _param(params, 'openid.' + param); | |
if(!_isDef(value)) | |
{ | |
return false; | |
@@ -789,11 +789,22 @@ function _checkSignature(params) | |
hmac.update(message); | |
var ourSignature = hmac.digest('base64'); | |
- if(ourSignature != params['openid.sig']) | |
+ if(ourSignature != _param(params, 'openid.sig')) | |
{ | |
- console.log('Signature mismatch: ' + ourSignature + ' != ' + params['openid.sig']); | |
+ console.log('Signature mismatch: ' + ourSignature + ' != ' + _param(params, 'openid.sig')); | |
return false; | |
} | |
return true; | |
} | |
+ | |
+// Recursive parameter lookup for node v0.2.x | |
+function _param(params, key) { | |
+ if (!params[key] && process.version.match(/^v0\.2\./)) { | |
+ var parts = key.split("."); | |
+ var first = parts.shift(); | |
+ return params[first] ? _param(params[first], parts.join(".")) : undefined; | |
+ } | |
+ | |
+ return params[key]; | |
+} | |
-- | |
1.7.0.4 | |
From 3dcfb30ed318dcbafa82d34627b93a72a80f0b43 Mon Sep 17 00:00:00 2001 | |
From: Ryan Probasco <ryan@bitdrift.org> | |
Date: Mon, 10 Jan 2011 21:13:57 -0700 | |
Subject: [PATCH 2/2] Use openid.claimed_id rather than openid.claimed_identifier | |
--- | |
openid.js | 2 +- | |
1 files changed, 1 insertions(+), 1 deletions(-) | |
diff --git a/openid.js b/openid.js | |
index b4155c9..5fac024 100644 | |
--- a/openid.js | |
+++ b/openid.js | |
@@ -732,7 +732,7 @@ openid.verifyAssertion = function(requestOrUrl) | |
return { authenticated: false, error: 'Provider signature is invalid or expired' }; | |
} | |
- return { authenticated : true , identifier: _param(assertionUrl.query, 'openid.claimed_identifier') }; | |
+ return { authenticated : true , identifier: _param(assertionUrl.query, 'openid.claimed_id') }; | |
} | |
function _getAssertionError(params) | |
-- | |
1.7.0.4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment