2012-04-06 20 views
2

In Ordnung, also versuche ich eine Bestätigung zu überprüfen, die von browserID zurückgegeben wird, um einen Benutzer anzumelden. Um dies zu tun, habe ich versucht, das browserid-verifier Paket zu verwenden. Ich konnte es jedoch nicht installieren. Es gibt einen Fehler in dem node-bigint Paket wie unten dargestellt:Wie überprüft man die Assertion von navigator.id.get in node.js?

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 

> [email protected] 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 [email protected] 
npm ERR! error installing [email protected] 
npm ERR! error installing [email protected] 

npm ERR! [email protected] install: `node-waf configure build` 
npm ERR! `sh "-c" "node-waf configure build"` failed with 1 
npm ERR! 
npm ERR! Failed at the [email protected] 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 [email protected] 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 

Anstatt also habe ich versucht, meinen eigenen Code zu schreiben, die Behauptung zu überprüfen. Das ist, was ich kam mit:

var mongoLife = "mongodb://nodejitsu:[email protected]: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); 

jedoch, wenn ein Benutzer anmelden versucht in mir die folgende Fehlermeldung erhalten:

[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) 

Jede Hilfe geschätzt wird. Alles, was ich versuche, ist eine HTTP-POST-Anfrage an https://browserid.org/ zu erstellen, die Assertion und die Zielgruppe zu übergeben und den Rückgabestatus zu überprüfen. Ich würde gerne genau wissen, wo ich falsch liege.

Antwort

1

Ich habe herausgefunden, was los war. In meinen Optionen hatte ich den Port auf 80 gesetzt. Da ich HTTPS verwende, sollte der Port 443 sein. Also habe ich den Port entfernt, damit er einen Standardport auswählen kann. Auch da es Daten in Chunks empfängt, habe ich nur alle Chunks in einer einzigen Nachricht gesammelt und die gesamte Nachricht analysiert, als sie empfangen wurde. Yay, ich bin so stolz auf mich.

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(); 
};