0

所以我一直在节点 0.8.20 上开发我的应用程序,并一直在使用护照进行谷歌身份验证。

我将节点更新到最新版本 0.10,但出现错误

_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'

我已经更新到最新版本的护照和护照谷歌模块,它似乎有帮助。

护照社区也没有就此提出任何问题。所以我认为这与我的代码有关。

更新: 好的,似乎此错误并非特定于节点 0.10。它从0.9开始存在。建议的解决方法是迁移到 google oauth。还没有解决方案

任何帮助都会很棒。

4

2 回答 2

3

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));
       }
于 2013-04-11T22:16:47.900 回答
1

Oki,所以这个错误似乎已经修复。但是找到了一种解决方法,可以使用passport-google模块下的现有代码

https://github.com/jaredhanson/passport-google-oauth/tree/master/examples/oauth2

问题已在护照 github 中提出。但是他们已经关闭指向解决方法而不是修复

于 2013-03-14T12:28:25.870 回答