2

好的,所以我正在尝试验证 browserID 返回的断言以登录用户。为此,我试图使用该browserid-verifier软件包。但是我无法安装它。包中有错误,node-bigint如下图:

npm http GET https://registry.npmjs.org/browserid-verifier
npm http 304 https://registry.npmjs.org/browserid-verifier
npm http GET https://registry.npmjs.org/jwcrypto/0.1.1
npm http GET https://registry.npmjs.org/express/2.5.1
npm http 304 https://registry.npmjs.org/jwcrypto/0.1.1
npm http 304 https://registry.npmjs.org/express/2.5.1
npm http GET https://registry.npmjs.org/mime
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/qs
npm http GET https://registry.npmjs.org/mkdirp/0.0.7
npm http GET https://registry.npmjs.org/browserify/1.8.1
npm http GET https://registry.npmjs.org/vows/0.5.13
npm http GET https://registry.npmjs.org/optimist/0.2.6
npm http GET https://github.com/benadida/node-bigint/tarball/2ac68
npm http 304 https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/qs
npm http 304 https://registry.npmjs.org/mkdirp/0.0.7
npm http 304 https://registry.npmjs.org/connect
npm http 304 https://registry.npmjs.org/browserify/1.8.1
npm http 304 https://registry.npmjs.org/vows/0.5.13
npm http GET https://registry.npmjs.org/formidable
npm http 304 https://registry.npmjs.org/optimist/0.2.6
npm http 200 https://github.com/benadida/node-bigint/tarball/2ac68

> bigint@0.3.7 install /home/aaditmshah/struggleforlife/node_modules/browserid-verifier/node_modules/jwcrypto/node_modules/bigint
> node-waf configure build

npm http GET https://registry.npmjs.org/wordwrap
npm http GET https://registry.npmjs.org/eyes
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for node path                   : not found 
Checking for node prefix                 : ok /usr 
'configure' finished successfully (0.022s)
Waf: Entering directory `/home/aaditmshah/struggleforlife/node_modules/browserid-verifier/node_modules/jwcrypto/node_modules/bigint/build'
[1/2] cxx: bigint.cc -> build/Release/bigint_1.o
npm http GET https://registry.npmjs.org/detective
npm http GET https://registry.npmjs.org/deputy
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/nub
npm http GET https://registry.npmjs.org/commondir
npm http GET https://registry.npmjs.org/coffee-script
npm http 304 https://registry.npmjs.org/formidable
../bigint.cc:9:17: fatal error: gmp.h: No such file or directory
compilation terminated.
Waf: Leaving directory `/home/aaditmshah/struggleforlife/node_modules/browserid-verifier/node_modules/jwcrypto/node_modules/bigint/build'
Build failed:  -> task failed (err #1): 
    {task: cxx bigint.cc -> bigint_1.o}
npm ERR! error installing bigint@0.3.7
npm ERR! error installing jwcrypto@0.1.1
npm ERR! error installing browserid-verifier@0.0.4

npm ERR! bigint@0.3.7 install: `node-waf configure build`
npm ERR! `sh "-c" "node-waf configure build"` failed with 1
npm ERR! 
npm ERR! Failed at the bigint@0.3.7 install script.
npm ERR! This is most likely a problem with the bigint package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-waf configure build
npm ERR! You can get their info via:
npm ERR!     npm owner ls bigint
npm ERR! There is likely additional logging output above.
npm ERR! 
npm ERR! System Linux 3.0.0-17-generic
npm ERR! command "node" "/usr/bin/npm" "install" "browserid-verifier"
npm ERR! cwd /home/aaditmshah/struggleforlife
npm ERR! node -v v0.6.14
npm ERR! npm -v 1.1.4
npm ERR! code ELIFECYCLE
npm ERR! message bigint@0.3.7 install: `node-waf configure build`
npm ERR! message `sh "-c" "node-waf configure build"` failed with 1
npm ERR! errno {}
npm http 304 https://registry.npmjs.org/resolve
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/aaditmshah/struggleforlife/npm-debug.log
npm not ok

因此,我尝试编写自己的代码来验证断言。这就是我想出的:

var mongoLife = "mongodb://nodejitsu:02a0f2d1cacb5259588ddfdfad59cf49@staff.mongohq.com:10088/nodejitsudb449201704656";

var querystring = require("querystring");
var mongoose = require("mongoose");
var express = require("express");
var https = require("https");
var nowjs = require("now");

mongoose.connect(mongoLife);
var app = express.createServer();
app.use(express.static(__dirname + "/public"));
var everyone = nowjs.initialize(app);

everyone.now.login = function (assertion) {
    var client = this.now;

    var postData = querystring.stringify({
        audience: "http://life.nodejitsu.com/",
        assertion: assertion
    });

    var options = {
        host: "browserid.org",
        path: "/verify",
        method: "POST",
        port: 80,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            "Content-Length": postData.length
        }
    };

    var request = https.request(options, function (response) {
        response.setEncoding("utf8");
        response.on("data", function (responseText) {
            var user = JSON.parse(responseText);
            client.loggedIn(user.status === "okay" ? user.email : null);
        });
    });

    request.write(postData);
    request.end();
};

var Schema = mongoose.Schema;
var ObjectId = Schema.ObjectId;

app.listen(8080);

但是,当用户尝试登录时,我收到以下错误:

[Error: 139723080664896:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:683:]
Error: 139723080664896:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:683:

    at CleartextStream._puller (tls.js:501:24)
    at CleartextStream._pull (tls.js:432:19)
    at SecurePair.cycle (tls.js:727:20)
    at EncryptedStream.write (tls.js:130:13)
    at Socket.ondata (stream.js:38:26)
    at Socket.emit (events.js:67:17)
    at TCP.onread (net.js:367:14)
{ [Error: socket hang up] code: 'ECONNRESET' }
Error: socket hang up
    at createHangUpError (http.js:1107:15)
    at CleartextStream.<anonymous> (http.js:1210:27)
    at CleartextStream.emit (events.js:88:20)
    at Array.0 (tls.js:792:22)
    at EventEmitter._tickCallback (node.js:192:40)

任何帮助将不胜感激。我要做的就是创建一个 HTTP POST 请求https://browserid.org/,传递断言和观众,并检查返回状态。我想确切地知道我哪里出错了。

4

1 回答 1

1

我发现出了什么问题。在我的选项中,我将端口设置为 80。由于我使用的是 HTTPS,因此端口应该是 443。所以我删除了端口以允许它选择默认端口。此外,由于它以块的形式接收数据,因此我只是将所有块收集到一条消息中,并在收到整个消息时对其进行解析。是的,我为自己感到骄傲。

everyone.now.login = function (assertion) {
    var client = this.now;

    var postData = querystring.stringify({
        audience: "http://life.nodejitsu.com/",
        assertion: assertion
    });

    var options = {
        host: "browserid.org",
        path: "/verify",
        method: "POST",
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            "Content-Length": postData.length
        }
    };

    var request = https.request(options, function (response) {
        var responseText = "";

        response.on("data", function (chunk) {
            responseText += chunk;
        });

        response.on("end", function () {
            var user = JSON.parse(responseText);
            client.loggedIn(user.status === "okay" ? user.email : null);
        });
    });

    request.write(postData);
    request.end();
};
于 2012-04-06T22:17:25.647 回答