So ive been developing my app on node 0.8.20 and been using passport for google authentication.
I updated my node to latest version 0.10 and i get an error
_modules\passport-openid\node_modules\openid\lib\convert.js:33
if(i.charCodeAt(0) > 127)
^
TypeError: Object n++n++:?n++9rn++??n++n+++ón++1??7q~n++n++qn++v#s?fn++?n++Z.'n+
has no method 'charCodeAt'
I have updated to latest version of passport and passport-google modules, and it dosent seem to help.
Also there is no issues raised on passport community regarding this. So i think its something to do with my code.
Update: Ok seem like this error is not specific to node 0.10. It exists from 0.9 . Suggested work around is to move to google oauth. No solution yet
Any help would be great.
It seems like the crypto module in node returns buffer objects instead of binary strings as default since version 0.9.0.
This diff will fix the problem:
diff --git node_modules/passport-google/node_modules/passport-openid/node_modules/openid/openid.js node_modules/passport-google/node_modules/passport-openid/node_modules/openid/openid.js
index 1431dd7..798f741 100644
--- node_modules/passport-google/node_modules/passport-openid/node_modules/openid/openid.js
+++ node_modules/passport-google/node_modules/passport-openid/node_modules/openid/openid.js
@@ -634,9 +634,9 @@ openid.associate = function(provider, callback, strict, algorithm)
if(algorithm.indexOf('no-encryption') === -1)
{
dh = _createDiffieHellmanKeyExchange(algorithm);
- params['openid.dh_modulus'] = _toBase64(dh.getPrime());
- params['openid.dh_gen'] = _toBase64(dh.getGenerator());
- params['openid.dh_consumer_public'] = _toBase64(dh.getPublicKey());
+ params['openid.dh_modulus'] = _toBase64(dh.getPrime("binary"));
+ params['openid.dh_gen'] = _toBase64(dh.getGenerator("binary"));
+ params['openid.dh_consumer_public'] = _toBase64(dh.getPublicKey("binary"));
}
_post(provider.endpoint, params, function(data, headers, statusCode)
@@ -713,10 +713,10 @@ openid.associate = function(provider, callback, strict, algorithm)
else
{
var serverPublic = _fromBase64(data.dh_server_public);
- var sharedSecret = convert.btwoc(dh.computeSecret(serverPublic));
+ var sharedSecret = convert.btwoc(dh.computeSecret(serverPublic, "binary", "binary"));
var hash = crypto.createHash(hashAlgorithm);
hash.update(sharedSecret);
- sharedSecret = hash.digest();
+ sharedSecret = hash.digest("binary");
var encMacKey = convert.base64.decode(data.enc_mac_key);
secret = convert.base64.encode(_xor(encMacKey, sharedSecret));
}
Oki, So this error dosent seem to have fixed. But found a workaround, which can work with the existing code under passport-google module
https://github.com/jaredhanson/passport-google-oauth/tree/master/examples/oauth2
Issue had been raised in passport github. But they have closed pointing to workaround rather than fix