Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just a quick demo to show browser ID login
- Loading branch information
0 parents
commit 184fdb7
Showing
2 changed files
with
83 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title></title> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | ||
<style> | ||
*{margin:0;padding:0;font-size:15px;font-family:helvetica,arial,sans-serif} | ||
footer,section,header{display:block;} | ||
h1{margin:2em} | ||
button,p{border:none;background:transparent;margin:0 2em;} | ||
</style> | ||
<script src="https://browserid.org/include.js"></script></head> | ||
<body> | ||
<header><h1>Darn it, I don't know you…</h1></header> | ||
<section> | ||
<button><img src="https://browserid.org/i/sign_in_green.png" alt="sign in with browser ID"></button> | ||
</section> | ||
<script> | ||
var request, | ||
but = document.querySelector('button'), | ||
h1 = document.querySelector('h1'); | ||
but.addEventListener('click', function(ev) { | ||
navigator.id.getVerifiedEmail(function(assertion) { | ||
if (assertion) { | ||
verify(assertion); | ||
} else { | ||
alert('I still don\'t know you...'); | ||
} | ||
}); | ||
function verify(assertion) { | ||
request = new XMLHttpRequest(); | ||
var parameters = 'assert=' + assertion; | ||
request.open('POST', 'verify.php'); | ||
request.setRequestHeader('If-Modified-Since', | ||
'Wed, 05 Apr 2006 00:00:00 GMT'); | ||
request.setRequestHeader('Content-type', | ||
'application/x-www-form-urlencoded'); | ||
request.setRequestHeader('Content-length', parameters.length); | ||
request.setRequestHeader('Connection', 'close'); | ||
request.send(encodeURI(parameters)); | ||
request.onreadystatechange = function() { | ||
if (request.readyState == 4){ | ||
if (request.status && (/200|304/).test(request.status)) { | ||
response = JSON.parse(request.responseText); | ||
if(response.status === 'okay') { | ||
message = 'Well, hi there, '+response.email; | ||
var p = document.createElement('p'); | ||
p.innerHTML = message; | ||
but.parentNode.replaceChild(p,but); | ||
h1.innerHTML = 'Woohoo, I know you!'; | ||
} | ||
} else{ | ||
alert('couldn\'t log you in. Sad panda now!'); | ||
} | ||
} | ||
}; | ||
} | ||
}, false); | ||
</script> | ||
</body> | ||
</html> |
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,16 @@ | ||
<?php | ||
|
||
$url = 'https://browserid.org/verify'; | ||
$assert = $_POST['assert']; | ||
$params = 'assertion='.$assert.'&audience=' . | ||
urlencode('http://thewebrocks.com'); | ||
$ch = curl_init(); | ||
curl_setopt($ch,CURLOPT_URL,$url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch,CURLOPT_POST,2); | ||
curl_setopt($ch,CURLOPT_POSTFIELDS, $params); | ||
$result = curl_exec($ch); | ||
curl_close($ch); | ||
echo $result; | ||
|
||
?> |