diff --git a/README.md b/README.md index 3db4a9f7d..1e7b32aa9 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,6 @@ And then start up browserid: SHIMMED_PRIMARIES="dev.fxaccounts.mozilla.org|http://127.0.0.1:3030|/tmp/fxwellknown" npm start -Now you can type foo@dev.fxaccounts.mozilla.org in the test dialog at http://127.0.0.1:10001/. No DNS or `/etc/hosts` hacks are needed. \ No newline at end of file +Now you can type foo@dev.fxaccounts.mozilla.org in the test dialog at http://127.0.0.1:10001/. No DNS or `/etc/hosts` hacks are needed. + +Password is 'asdf'. \ No newline at end of file diff --git a/server/bin/firefox_account_bridge.js b/server/bin/firefox_account_bridge.js index 9122233a0..7d081999a 100755 --- a/server/bin/firefox_account_bridge.js +++ b/server/bin/firefox_account_bridge.js @@ -12,6 +12,7 @@ const clientSessions = require('client-sessions'), config = require('../lib/configuration'), express = require('express'), nunjucks = require('nunjucks'), + routes = require('../lib/routes'), urlparse = require('urlparse'), util = require('util'); @@ -52,24 +53,9 @@ app.use(function(req, resp, next) { next(); }); -app.get('/.well-known/browserid', function(req, res) { - res.setHeader('Content-Type', 'application/json'); - res.render('browserid.html'); -}); - -app.get('/provision', function(req, res) { - res.render('provision.html', { - browserid_server: config.get('browserid_server'), - provisioned: false - }); -}); +routes(app); -app.get('/authentication', function(req, res) { - res.render('authentication.html', { - browserid_server: config.get('browserid_server'), - currentEmail: 'null' - }); -}); +app.use(express.static(path.join(process.cwd(), '..', 'static'))); if (config.get('use_https')) { // Development only... Ops runs this behind nginx @@ -87,6 +73,7 @@ if (config.get('use_https')) { } else { port = config.get('port'); app.listen(port, '0.0.0.0'); + console.log('config.get("issuer")', config.get('issuer')); lstnUrl = util.format('http://%s:%s', config.get('issuer'), port); } console.log('Firefox Account Bridge listening at', lstnUrl); diff --git a/server/lib/routes.js b/server/lib/routes.js new file mode 100644 index 000000000..102630008 --- /dev/null +++ b/server/lib/routes.js @@ -0,0 +1,52 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +const config = require('../lib/configuration'); + +module.exports = function(app) { + app.get('/.well-known/browserid', function(req, res) { + res.setHeader('Content-Type', 'application/json'); + res.render('browserid.html'); + }); + + app.get('/provision', function(req, res) { + var provisioned = req.session.emails || []; + res.render('provision.html', { + browserid_server: config.get('browserid_server'), + provisioned: JSON.stringify(provisioned) + }); + }); + + app.post('/provision', function(req, res) { + res.setHeader('Content-Type', 'application/json'); + var email = req.body.email, + publicKey = req.body.publicKey, + duration = req.body.duration; + var certificate = 'TODO'; + res.send(JSON.stringify({ + certificate: certificate + })); + }); + + app.get('/authentication', function(req, res) { + res.render('authentication.html', { + browserid_server: config.get('browserid_server'), + currentEmail: 'null' + }); + }); + + app.post('/authentication', function(req, res) { + res.setHeader('Content-Type', 'application/json'); + if ('asdf' === req.body.password && + 'foo@dev.fxaccounts.mozilla.org' === req.body.email) { + if (! req.session.emails) { + req.session.emails = []; + } + req.session.emails.push(req.body.email); + res.send(JSON.stringify({status: "OK"})); + } else { + res.send(JSON.stringify({error: "Wrong username or password"}), 403); + } + }); +}; \ No newline at end of file diff --git a/server/views/authentication.html b/server/views/authentication.html index b9d80c7bc..e1c3400a6 100644 --- a/server/views/authentication.html +++ b/server/views/authentication.html @@ -4,7 +4,7 @@