oauth2-client-demo/login.html

67 lines
2.6 KiB
HTML
Raw Normal View History

2018-02-08 16:11:19 +00:00
<html>
<head>
2018-02-08 16:24:05 +00:00
<meta charset="utf-8">
2018-02-08 16:11:19 +00:00
<title>OAuth2 Demo Login</title>
2018-02-08 16:38:15 +00:00
<link rel="stylesheet" href="brutalist.css" />
2018-02-09 06:45:04 +00:00
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
2018-02-08 16:11:19 +00:00
</head>
<body>
<script>
function getJsonFromUrl() {
2018-02-08 16:52:14 +00:00
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;
2018-02-08 16:11:19 +00:00
</script>
<h1>Yolo App login page</h1>
<p>Authorization process done!</p>
2018-02-08 16:24:05 +00:00
<a href="/index.html">← go back to main page</a>
2018-02-09 16:01:06 +00:00
<h2>Tokens</h2>
<pre id="token" class="code">Retrive tokens...</pre>
<h2>Decoded Code:</h2>
2018-02-08 16:52:14 +00:00
<pre class="code"><script>document.write(JSON.stringify(jwt,null,2));</script></pre>
2018-02-09 16:01:06 +00:00
<h2>decoded from the code:</h2>
2018-02-08 16:11:19 +00:00
<pre class="code"><script>document.write(params.code);</script></pre>
2018-02-09 06:45:04 +00:00
<script>
var tokparams={
"code":params.code
, "redirect_uri":"http://localhost:9999/login.html"
, "scope":"ctia iroh-collect"
, "client_id":"localtest"
, "grant_type":"authorization_code"
};
2018-02-09 16:01:06 +00:00
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));}
2018-02-09 11:33:10 +00:00
$.ajax({
type: "POST"
, beforeSend: function(request) {request.setRequestHeader("Authorization","Basic localpass")}
2018-02-09 16:01:06 +00:00
, success: onTokenSuccess
, error: onTokenError
2018-02-09 11:33:10 +00:00
, url: "http://localhost:9001/iroh/oauth2/token"
, data: tokparams
, contentType: 'application/x-www-form-urlencoded; charset=UTF-8'
, crossDomain: true
});
2018-02-09 06:45:04 +00:00
</script>
2018-02-08 16:11:19 +00:00
</body>
</html>