diff --git a/.gitignore b/.gitignore index d92c19c88b771f93c86183ed55afa7be9be09ba8..a03c5e3933569d05747d2a3e1219fbce7da36a60 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ \#*\# .\#* +node_modules diff --git a/README.md b/README.md index f689e8839da267f2c18edf4b13a1231b8aedc8bc..b2d950e1d12153d138969f5cda4c5c39b29380e2 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,15 @@ This is an exploration of the distributed identity system All of the servers here are based on node.js, and some number of 3rd party node modules are required to make them go. ([npm](http://npmjs.org/) is a good way to get these libraries) * node.js (>= 0.4.5): http://nodejs.org/ -* express (>= 2.3.11): http://senchalabs.github.com/express/ -* xml2js (>= 0.1.5) -* sqlite (>= 1.0.3) -* mustache (>= 0.3.1) -* cookie-sessions (>= 0.0.2) -* nodemailer (>= 0.1.18) -* vows (>= 0.5.8) -* bcrypt (>= 0.2.3) -* ejs (>= 0.4.3) -* temp (>= 0.2.0) -* express-csrf (>= 0.3.2) -* uglify-js (>= 1.0.6) +* Several node.js 3rd party libraries - check `package.json` for details + ## Getting started: -1. install required software -2. run the top level *run.js* script: `node ./run.js` -3. visit the demo application ('rp') in your web browser (url output on the console at runtime)â +1. install node +2. run `npm install` to installed 3rd party libraries into `node_modules` +3. run the top level *run.js* script: `node ./run.js` +4. visit the demo application ('rp') in your web browser (url output on the console at runtime)â ## Testing diff --git a/browserid/lib/wsapi.js b/browserid/lib/wsapi.js index a2a92233830ebaa4358d36e773c2850271072761..d01b952b78b2dd4311b35065fe13bb9d3290e657 100644 --- a/browserid/lib/wsapi.js +++ b/browserid/lib/wsapi.js @@ -54,7 +54,7 @@ function setup(app) { // get inputs from get data! var email = url.parse(req.url, true).query['email']; db.emailKnown(email, function(known) { - httputils.jsonResponse(resp, known); + resp.json(known); }); }); @@ -87,7 +87,7 @@ function setup(app) { // served over an encrypted (SSL) session. guten, yah. }; - httputils.jsonResponse(resp, true); + resp.json(true); // let's now kick out a verification email! email.sendVerificationEmail(stageParams.email, stageParams.site, secret); @@ -121,9 +121,9 @@ function setup(app) { function(registered) { if (registered) { delete req.session.pendingAddition; - httputils.jsonResponse(resp, "complete"); + resp.json('complete'); } else { - httputils.jsonResponse(resp, "pending"); + resp.json('pending'); } }); } else { @@ -134,9 +134,9 @@ function setup(app) { if (hash === v.hash) { delete req.session.pendingVerification; req.session.authenticatedUser = v.email; - httputils.jsonResponse(resp, "complete"); + resp.json('complete'); } else { - httputils.jsonResponse(resp, "pending"); + resp.json('pending'); } }); } @@ -154,7 +154,8 @@ function setup(app) { if (!req.session) req.session = {}; req.session.authenticatedUser = req.body.email; } - httputils.jsonResponse(resp, success); + + resp.json(success); }); }); @@ -166,7 +167,7 @@ function setup(app) { // store the email being added in session data req.session.pendingAddition = req.body.email; - httputils.jsonResponse(resp, true); + resp.json(true); // let's now kick out a verification email! email.sendVerificationEmail(req.body.email, req.body.site, secret); @@ -185,7 +186,7 @@ function setup(app) { console.log("error removing email " + email); httputils.badRequest(resp, error.toString()); } else { - httputils.jsonResponse(resp, true); + resp.json(true); }}); }); @@ -195,13 +196,13 @@ function setup(app) { console.log("error cancelling account : " + error.toString()); httputils.badRequest(resp, error.toString()); } else { - httputils.jsonResponse(resp, true); + resp.json(true); }}); }); app.post('/wsapi/set_key', checkAuthed, checkParams(["email", "pubkey"]), function (req, resp) { db.addKeyToEmail(req.session.authenticatedUser, req.body.email, req.body.pubkey, function (rv) { - httputils.jsonResponse(resp, rv); + resp.json(rv); }); }); @@ -209,18 +210,18 @@ function setup(app) { // if they're authenticated for an email address that we don't know about, // then we should purge the stored cookie if (!isAuthed(req)) { - httputils.jsonResponse(resp, false); + resp.json(false); } else { db.emailKnown(req.session.authenticatedUser, function (known) { if (!known) req.session = {} - httputils.jsonResponse(resp, known); + resp.json(known); }); } }); app.post('/wsapi/logout', function(req,resp) { req.session = {}; - httputils.jsonResponse(resp, "ok"); + resp.json('ok'); }); app.post('/wsapi/sync_emails', checkAuthed, function(req,resp) { @@ -228,7 +229,7 @@ function setup(app) { db.getSyncResponse(req.session.authenticatedUser, emails, function(err, syncResponse) { if (err) httputils.serverError(resp, err); - else httputils.jsonResponse(resp, syncResponse); + else resp.json(syncResponse); }); }); @@ -236,9 +237,9 @@ function setup(app) { db.gotVerificationSecret(req.query.token, function(e) { if (e) { console.log("error completing the verification: " + e); - httputils.jsonResponse(resp, false); + resp.json(false); } else { - httputils.jsonResponse(resp, true); + resp.json(true); } }); }); diff --git a/package.json b/package.json new file mode 100644 index 0000000000000000000000000000000000000000..78fdad42fca3a034200031b76e68b1a78cbccad4 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "browserid" + , "version": "0.0.1" + , "private": true + , "dependencies": { + "express": "2.4.3" + , "xml2js": "0.1.5" + , "sqlite": "1.0.3" + , "nodemailer": "0.1.18" + , "mustache": "0.3.1-dev" + , "cookie-sessions": "0.0.2" + , "vows": "0.5.8" + , "bcrypt": "0.2.3" + , "ejs": "0.4.3" + , "temp": "0.2.0" + , "express-csrf": "0.3.2" + , "uglify-js": "1.0.6" + } +} \ No newline at end of file diff --git a/primary/lib/wsapi.js b/primary/lib/wsapi.js index 16ac8c90c6f0a132ec96eab66e6d28ee077f5476..7de31c829bcea6144e8cb2a6e67543c6651d72de 100644 --- a/primary/lib/wsapi.js +++ b/primary/lib/wsapi.js @@ -47,7 +47,7 @@ exports.username_available = function(req, resp) { var username = normalizeUsername(url.parse(req.url, true).query['username']); logRequest("username_available", {username: username}); db.usernameKnown(username, function(known) { - httputils.jsonResponse(resp, known); + resp.json(known); }); }; @@ -66,12 +66,12 @@ exports.create_user = function(req, resp) { db.create_user(normalized_username, getArgs["pass"], function(error) { if (error) { logRequest("create_user", error); - httputils.jsonResponse(resp, undefined); + resp.json(undefined); } else { if (!req.session) req.session = {}; db.usernameToUserID(normalized_username, function(userid) { req.session.userid = userid; - httputils.jsonResponse(resp, {username: normalized_username, id: userid}); + resp.json({ username: normalized_username, id: userid }); }); } }); @@ -95,7 +95,7 @@ exports.authenticate_user = function(req, resp) { req.session.userid = userid; } var rp = {username: normalized_username, status: userid != null}; - httputils.jsonResponse(resp, rp); + resp.json(rp); }); }; @@ -104,7 +104,7 @@ exports.signout = function(req, resp) { if (req.session) { req.session.userid = undefined;// can I reference undefined safely like this? } - httputils.jsonResponse(resp, {}); + resp.json({}); }; exports.add_key = function (req, resp) { @@ -123,13 +123,13 @@ exports.add_key = function (req, resp) { logRequest("add_key", getArgs); db.addKeyToAccount(req.session.userid, getArgs.pubkey, function (rv) { logRequest("add_key", "Success"); - httputils.jsonResponse(resp, rv); + resp.json(rv); }); }; exports.am_authed = function(req,resp) { logRequest("am_authed", req.session); - httputils.jsonResponse(resp, isAuthed(req)); + resp.json(isAuthed(req)); }; exports.current_username = function(req,resp) { @@ -140,16 +140,16 @@ exports.current_username = function(req,resp) { db.userIDToUsername(req.session.userid, function(username) { if (username !== undefined) { logRequest("current_username", username); - httputils.jsonResponse(resp, username); + resp.json(username); } else { logRequest("current_username", "userid doesn't exist: " + req.session.userid); req.session.userid = undefined; - httputils.jsonResponse(resp, false); + resp.json(false); } }); } else { logRequest("current_username", "notAuthed"); - httputils.jsonResponse(resp, false); + resp.json(false); } } catch (e) { console.log(e); diff --git a/verifier/app.js b/verifier/app.js index 4fbd67b20f4cdcd56d8e9050e1ada6482eca6a50..2503a31be9d9a96453519c08f6a5a04623e69773 100644 --- a/verifier/app.js +++ b/verifier/app.js @@ -15,7 +15,7 @@ function doVerify(req, resp, next) { var audience = (req.query && req.query.audience) ? req.query.audience : req.body.audience; if (!(assertion && audience)) - return httputils.jsonResponse(resp, {status:"failure", reason:"need assertion and audience"}); + return resp.json({ status: "failure", reason: "need assertion and audience" }); // allow client side XHR to access this WSAPI, see // https://developer.mozilla.org/en/http_access_control @@ -42,15 +42,15 @@ function doVerify(req, resp, next) { "valid-until" : payload["valid-until"], issuer : payload.issuer }; - httputils.jsonResponse(resp, result); + resp.json(result); }, function(errorObj) { - httputils.jsonResponse(resp, {status:"failure", reason:errorObj}); + resp.json({ status: "failure", reason: errorObj }); } ); } catch (e) { console.log(e.stack); - httputils.jsonResponse(resp, {status:"failure", reason:e.toString()}); + resp.json({ status: "failure", reason: e.toString() }); } }