This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
/
provision.html
55 lines (51 loc) · 1.98 KB
/
provision.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<!-- 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/. -->
<html>
<head>
<script type="text/javascript" src="https://login.persona.org/provisioning_api.js"></script>
<script type="text/javascript" src="/jquery.js"></script>
<script type="text/javascript">
// begin provisioning! This both gives us indicated to browserid that we're
// a well formed provisioning page and gives us the parameters of the provisioning
navigator.id.beginProvisioning(function(email, cert_duration) {
var user = /^([^@]+)@/.exec(email)[1];
// now we have the email address that wishes to be provisioned!
// is he authenticated to eyedee.me?
$.get('/api/whoami')
.success(function(who) {
if (user != who) {
return navigator.id.raiseProvisioningFailure('user is not authenticated as target user');
}
// Awesome! The user is authenticated as who we want to provision. let's
// generate a keypair
navigator.id.genKeyPair(function(pubkey) {
// finally, once we have a public key from the browser, we'll certify it, and
// go pass it back
$.ajax({
url: '/api/cert_key',
data: JSON.stringify({
pubkey: JSON.parse(pubkey),
duration: cert_duration
}),
type: 'POST',
headers: { "Content-Type": 'application/json' },
dataType: 'json',
success: function(r) {
// all done! woo!
navigator.id.registerCertificate(r.cert);
},
error: function(r) {
navigator.id.raiseProvisioningFailure("couldn't certify key");
}
});
});
})
.error(function() {
navigator.id.raiseProvisioningFailure('user is not authenticated');
});
});
</script>
</head>
</html>