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-04-16 14:09:37 +00:00
|
|
|
<script src="./infos.js"></script>
|
2018-02-08 16:11:19 +00:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
|
|
|
</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-20 12:46:01 +00:00
|
|
|
<h2>Authorization Status</h2>
|
|
|
|
<pre class="code" id="authorization_status"></pre>
|
2018-02-20 12:59:48 +00:00
|
|
|
<div id="error-info"></div>
|
2018-02-20 12:46:01 +00:00
|
|
|
<h3>State</h3>
|
|
|
|
The process should also return the state provided.
|
|
|
|
<pre class="code" id="state-param"></pre>
|
2018-05-09 15:25:49 +00:00
|
|
|
<div id="onaccesstoken">
|
|
|
|
<h2>Access Token</h2>
|
|
|
|
<p>The access token is generated by the Authentication server and
|
|
|
|
send back to the client via the resource's owner user-agent</p>
|
|
|
|
<p>Access tokens live a short time (about 10 min to 1 hour)</p>
|
2018-02-20 13:03:40 +00:00
|
|
|
<p>For us, it is a JWT:</p>
|
2018-05-09 15:25:49 +00:00
|
|
|
<pre class="code" id="accesstoken-param"></pre>
|
2018-02-20 13:03:40 +00:00
|
|
|
<p>Which once decoded is:</p>
|
2018-05-09 15:25:49 +00:00
|
|
|
<pre class="code" id="accesstoken-token"></pre>
|
2018-02-20 13:03:40 +00:00
|
|
|
<h2>Using the API</h2>
|
2018-05-09 15:25:49 +00:00
|
|
|
<h2>API Call</h2>
|
|
|
|
<p>API URL: <code id="apiurl" class="code">Nothing yet.</code></p>
|
2018-02-20 13:03:40 +00:00
|
|
|
<div class="button"
|
|
|
|
onclick="makeApiCall();">
|
|
|
|
Make an API call with the access token
|
|
|
|
</div>
|
2018-04-24 11:41:53 +00:00
|
|
|
<p>API URL: <code id="apiurl" class="code">Nothing yet.</code></p>
|
2018-02-20 13:03:40 +00:00
|
|
|
<pre id="apiresponse" class="code">Nothing yet.</pre>
|
2018-02-13 16:56:05 +00:00
|
|
|
</div>
|
2018-02-09 06:45:04 +00:00
|
|
|
<script>
|
2018-02-28 09:42:24 +00:00
|
|
|
/* ----- */
|
2018-02-20 12:46:01 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-05-09 15:25:49 +00:00
|
|
|
function getHashParams() {
|
|
|
|
var hashParams={};
|
|
|
|
var e,
|
|
|
|
a = /\+/g, // Regex for replacing addition symbol with a space
|
|
|
|
r = /([^&;=]+)=?([^&;]*)/g,
|
|
|
|
d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
|
|
|
|
q = window.location.hash.substring(1);
|
|
|
|
while (e = r.exec(q))
|
|
|
|
hashParams[d(e[1])] = d(e[2]);
|
|
|
|
return hashParams;
|
|
|
|
}
|
|
|
|
var params=getHashParams();
|
2018-02-20 12:46:01 +00:00
|
|
|
var authstatus="";
|
|
|
|
if (params.error) {
|
|
|
|
authstatus = "REFUSED: " + params.error;
|
2018-04-23 13:23:56 +00:00
|
|
|
if (params.error_description) {
|
|
|
|
authstatus += "\n\n" + params.error_description;
|
|
|
|
}
|
2018-05-04 16:35:45 +00:00
|
|
|
if (params.invalid_parameter) {
|
|
|
|
authstatus += "\n\nInvalid parameter: " + params.invalid_parameter;
|
|
|
|
}
|
2018-04-23 13:23:56 +00:00
|
|
|
if (params.error_uri) {
|
2018-05-04 16:35:45 +00:00
|
|
|
authstatus += "\n\n<a href='" + decodeURIComponent(params.error_uri) + "'>" + decodeURIComponent(params.error_uri) + "</a>";
|
2018-04-23 13:23:56 +00:00
|
|
|
}
|
2018-02-20 12:46:01 +00:00
|
|
|
$('#authorization_status').addClass('refused');
|
2018-05-09 15:25:49 +00:00
|
|
|
$('#onaccesstoken').hide();
|
2018-02-20 12:46:01 +00:00
|
|
|
} else {
|
2018-05-09 15:25:49 +00:00
|
|
|
if (params.access_token) {
|
2018-02-21 16:49:20 +00:00
|
|
|
authstatus = "AUTHORIZED" ;
|
|
|
|
$('#authorization_status').addClass('authorized');
|
|
|
|
} else {
|
|
|
|
authstatus = "UNKNOWN" ;
|
2018-05-09 15:25:49 +00:00
|
|
|
$('#onaccesstoken').hide();
|
2018-02-21 16:49:20 +00:00
|
|
|
$('#state-param').html("No state");
|
|
|
|
}
|
2018-02-20 12:46:01 +00:00
|
|
|
}
|
2018-04-24 11:41:53 +00:00
|
|
|
$('#urltoken').html( oauthServerTokenUrl );
|
|
|
|
$('#apiurl').html( resourceProviderTestEndpoint );
|
2018-02-20 12:46:01 +00:00
|
|
|
$('#authorization_status').html( authstatus );
|
|
|
|
$('#state-param').html(params.state);
|
2018-02-20 12:59:48 +00:00
|
|
|
if (params.error_uri) {
|
|
|
|
var erroruri=decodeURIComponent(params.error_uri);
|
|
|
|
$('#error-info').html("<p>You can have more informations here:</p><a href=\"" + erroruri + "\" target=\"_blank\">" + erroruri + "</a>");
|
|
|
|
}
|
2018-02-20 12:46:01 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2018-05-09 15:25:49 +00:00
|
|
|
var jwt=jwtDecode(params.access_token).payload;
|
|
|
|
$('#accesstoken-param').html(params.access_token);
|
|
|
|
$('#accesstoken-token').html(JSON.stringify(jwt,null,2));
|
|
|
|
var accessToken=params.access_token;
|
2018-02-13 17:24:01 +00:00
|
|
|
var makeApiCall = function() {
|
2018-02-13 17:34:42 +00:00
|
|
|
var onError = function(jqXHR,textStatus,errorThrown){
|
2018-02-13 17:24:01 +00:00
|
|
|
$('#apiresponse').html(errorThrown + " status: " + jqXHR.status
|
|
|
|
+ "\n---\n"
|
|
|
|
+ JSON.stringify(jqXHR.responseJSON,null,2))}
|
2018-02-13 17:34:42 +00:00
|
|
|
var onSuccess = function(data,textStatus,jqXHR) {
|
2018-02-13 17:24:01 +00:00
|
|
|
$("#apiresponse").html(data
|
|
|
|
+ "\n---\n"
|
|
|
|
+ JSON.stringify(jqXHR.responseJSON,null,2));}
|
|
|
|
$.ajax({
|
|
|
|
type: "GET"
|
|
|
|
, beforeSend: function(request) {request.setRequestHeader("Authorization","Bearer " + accessToken)}
|
2018-02-13 17:34:42 +00:00
|
|
|
, success: onSuccess
|
|
|
|
, error: onError
|
2018-04-19 14:43:15 +00:00
|
|
|
, url: resourceProviderTestEndpoint
|
2018-02-13 17:24:01 +00:00
|
|
|
, contentType: 'application/json'
|
|
|
|
, crossDomain: true
|
|
|
|
});
|
|
|
|
};
|
2018-02-09 06:45:04 +00:00
|
|
|
</script>
|
2018-02-08 16:11:19 +00:00
|
|
|
</body>
|
|
|
|
</html>
|