Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
211 lines (184 sloc) 7.04 KB
<style>
pre {
padding: 5px;
margin: 5px;
}
.string {
color: green;
}
.number {
color: darkorange;
}
.boolean {
color: blue;
}
.null {
color: magenta;
}
.key {
color: red;
}
</style>
<h2>Claims!</h2>
<h3>Valid User With Serious Claims Section</h3>
<div>
<button type="button" onclick="validUserWithSeriousClaimsLogin()">Log in as Valid User With Serious Claims!</button>
</div>
<br />
<div>
<button type="button" onclick="requestValidUserWithSeriousClaimsData()">Request Valid User With Serious Claims data</button>
</div>
<hr />
<h3>Valid User Without Any Serious Claims Section</h3>
<div>
<button type="button" onclick="validUserWithoutAnySeriousClaimsLogin()">Log in as Valid User Without Any Serious Claims!</button>
</div>
<br />
<div>
<button type="button" onclick="requestValidUserWithoutAnySeriousClaimsData()">Request Valid User Without Any Serious Claims data</button>
</div>
<br />
<div>
<button type="button" onclick="requestValidUserWithSeriousClaimsData()">Request Valid User WITH Serious Claims data but as Valid User WITHOUT Any Serious Claims</button>
</div>
<hr />
<h3>Invalid User Token Section</h3>
<div>
<button type="button" onclick="generateInvalidUserToken()">Request an Invalid Token</button>
</div>
<br />
<div>
<button type="button" onclick="requestInvalidUserData()">Request Invalid User Data</button>
</div>
<hr />
<h2>Response Received:</h2>
<p id="response"></p>
<script>
// Utility method for pretty printing JSON
function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace( />/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
// --------- Valid User With Serious Claims Start ---------------------
function validUserWithSeriousClaimsLogin() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === 4 && xhttp.status === 200) {
var response = JSON.parse(xhttp.responseText);
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = syntaxHighlight(JSON.stringify(response, undefined, 4));
// Save the JWT token in the browser's local storage.
window.localStorage.setItem("jwt", response.access_token);
}
};
xhttp.open("POST", "http://localhost:16137/api/Account/ValidUserWithSeriousClaimsLogin", false);
xhttp.send();
};
function requestValidUserWithSeriousClaimsData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === 4) {
if (xhttp.status === 200) {
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = xhttp.responseText;
} else {
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = 'Request failed: ' + xhttp.statusText + '(' + xhttp.status + ')';
}
}
};
xhttp.open("GET", "http://localhost:16137/api/Resource/ValidUserWithSeriousClaimsData", false);
// Add the JWT to the request as an Authorization header, note the space between
// 'Bearer' and the token value!
xhttp.setRequestHeader('Authorization', 'Bearer ' + window.localStorage.getItem("jwt"));
xhttp.send();
};
// --------- Valid User With Serious Claims End -----------------------
// ---- Valid User Without Any Serious Claims Start -------------------
function validUserWithoutAnySeriousClaimsLogin() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === 4 && xhttp.status === 200) {
var response = JSON.parse(xhttp.responseText);
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = syntaxHighlight(JSON.stringify(response, undefined, 4));
// Save the JWT token in the browser's local storage.
window.localStorage.setItem("jwt", response.access_token);
}
};
xhttp.open("POST", "http://localhost:16137/api/Account/ValidUserWithoutAnySeriousClaimsLogin", false);
xhttp.send();
};
function requestValidUserWithoutAnySeriousClaimsData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === 4) {
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "http://localhost:16137/api/Resource/ValidUserWithoutAnySeriousClaimsData", false);
// Add the JWT to the request as an Authorization header, note the space between
// 'Bearer' and the token value!
xhttp.setRequestHeader('Authorization', 'Bearer ' + window.localStorage.getItem("jwt"));
xhttp.send();
};
// ---- Valid User Without Any Serious Claims End ---------------------
// ------------- Invalid User Token Start -----------------------------
function generateInvalidUserToken() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === 4 && xhttp.status === 200) {
var response = JSON.parse(xhttp.responseText);
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = syntaxHighlight(JSON.stringify(response, undefined, 4));
// Save the JWT token in the browser's local storage.
window.localStorage.setItem("jwt", response.access_token);
}
};
xhttp.open("POST", "http://localhost:16137/api/Account/GenerateInvalidValidUserToken", false);
xhttp.send();
};
function requestInvalidUserData() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState === 4) {
if (xhttp.status === 200) {
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = xhttp.responseText;
} else {
document.getElementById("response")
.appendChild(document.createElement('pre'))
.innerHTML = 'Request failed: ' + xhttp.statusText + '(' + xhttp.status + ')';
}
}
};
xhttp.open("GET", "http://localhost:16137/api/Resource/InvalidUserData", false);
// Add the JWT to the request as an Authorization header, note the space between
// 'Bearer' and the token value!
xhttp.setRequestHeader('Authorization', 'Bearer ' + window.localStorage.getItem("jwt"));
xhttp.send();
};
// ------------- Invalid User Token End -------------------------------
</script>