oauth2-client-demo/login.html
Yann Esposito (Yogsototh) 2f9a507803
cleaner page
2018-02-09 17:01:06 +01:00

66 lines
2.6 KiB
HTML

<html>
<head>
<meta charset="utf-8">
<title>OAuth2 Demo Login</title>
<link rel="stylesheet" href="brutalist.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<script>
function getJsonFromUrl() {
var query = location.search.substr(1);
var result = {};
query.split("&").forEach(function(part) {
var item = part.split("=");
result[item[0]] = decodeURIComponent(item[1]);
});
return result;
}
var params=getJsonFromUrl();
function jwtDecode(t) {
let token = {};
token.raw = t;
token.header = JSON.parse(window.atob(t.split('.')[0]));
token.payload = JSON.parse(window.atob(t.split('.')[1]));
return (token)
}
var jwt=jwtDecode(params.code).payload;
</script>
<h1>Yolo App login page</h1>
<p>Authorization process done!</p>
<a href="/index.html">← go back to main page</a>
<h2>Tokens</h2>
<pre id="token" class="code">Retrive tokens...</pre>
<h2>Decoded Code:</h2>
<pre class="code"><script>document.write(JSON.stringify(jwt,null,2));</script></pre>
<h2>decoded from the code:</h2>
<pre class="code"><script>document.write(params.code);</script></pre>
<script>
var tokparams={
"code":params.code
, "redirect_uri":"http://localhost:9999/login.html"
, "scope":"ctia iroh-collect"
, "client_id":"localtest"
, "grant_type":"authorization_code"
};
var onTokenError = function(jqXHR,textStatus,errorThrown){
$('#token').html(errorThrown + " status: " + jqXHR.status
+ "\n---\n"
+ JSON.stringify(jqXHR.responseJSON,null,2))}
var onTokenSuccess = function(data,textStatus,jqXHR) {
$("#token").html(data
+ "\n---\n"
+ JSON.stringify(jqXHR.responseJSON,null,2));}
$.ajax({
type: "POST"
, beforeSend: function(request) {request.setRequestHeader("Authorization","Basic localpass")}
, success: onTokenSuccess
, error: onTokenError
, url: "http://localhost:9001/iroh/oauth2/token"
, data: tokparams
, contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
, crossDomain: true
});
</script>
</body>
</html>