Last active
December 15, 2015 02:19
-
-
Save kamituel/5186602 to your computer and use it in GitHub Desktop.
Mozilla Persona provision page
This file contains hidden or 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
<?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