Skip to content

Instantly share code, notes, and snippets.

@kamituel
Last active December 15, 2015 02:19
Show Gist options
  • Save kamituel/5186602 to your computer and use it in GitHub Desktop.
Save kamituel/5186602 to your computer and use it in GitHub Desktop.
Mozilla Persona provision page
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<script src="https://login.persona.org/provisioning_api.js"></script>
<script>
<?php require('session.php'); ?>
var generateServerSide = function (email, publicKey, certDuration, cbk) {
var oReq = new XMLHttpRequest();
oReq.onload = function () {
cbk(JSON.parse(oReq.responseText).certificate);
};
var certServerUrl = "http://example.com/cert_key";
oReq.open("post", certServerUrl, false);
oReq.setRequestHeader('Content-Type', 'application/json');
var certSignReq = '{"duration": ' + certDuration + ', "email": "' + email + '", "pubkey": "' + publicKey.replace(/"/g, '\\"') +'"}';
oReq.send(certSignReq);
};
navigator.id.beginProvisioning(function(email, certDuration) {
if (activeSessionFor(email)) {
navigator.id.genKeyPair(function(publicKey) {
generateServerSide(email, publicKey, certDuration, function (certificate) {
navigator.id.registerCertificate(certificate);
});
});
} else {
navigator.id.raiseProvisioningFailure('user is not authenticated as target user');
}
});
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment