This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mozilla/fake-auth
Sketching in fake auth with hardcoded email and password
- Loading branch information
Showing
6 changed files
with
104 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,24 @@ | ||
<!DOCTYPE html> | ||
<script src="{{browserid_server}}/provisioning_api.js"></script> | ||
<script src="/js/vendor/jquery-1.7.1.min.js"></script> | ||
<script> | ||
var provisioned = {{ provisioned }}; | ||
console.log(navigator.id.beginProvisioning); | ||
navigator.id.beginProvisioning(function(email, certDuration) { | ||
{% if provisioned %} | ||
if (provisioned.indexOf(email) !== -1) { | ||
navigator.id.genKeyPair(function(publicKey) { | ||
generateServerSide(email, publicKey, certDuration, function (certificate) { | ||
// generateServerSide something you would write. | ||
// In this example, imagine it does an AJAX request to create a certificate, | ||
// and then invokes a callback with that certificate. | ||
$.post('/provision', { | ||
email: email, | ||
publicKey: publicKey, | ||
duration: certDuration, | ||
_csrf: "{{ csrf_token }}" | ||
}, function (data) { | ||
var certificate = data.certificate; | ||
navigator.id.registerCertificate(certificate); | ||
}); | ||
}); | ||
{% else %} | ||
} else { | ||
navigator.id.raiseProvisioningFailure('user is not authenticated as target user'); | ||
{% endif %} | ||
} | ||
}); | ||
</script> | ||
</script> |
Large diffs are not rendered by default.
Oops, something went wrong.