I have an HTML page where a user can access a Web API 2 webservice to get some data. This HTML page is not part of the MVC application, but is a standalone HTML page, that can be on any web server or local OS.
Before the user can get the data, the user has to request a token with the following code:
function login()
{
self.result = '';
var loginData = {
grant_type: 'password',
username: document.getElementById("loginEmailTest").value,
password: document.getElementById("loginPasswordTest").value
};
$.ajax({
type: 'POST',
url: 'https://localhost/token/Token',
data: loginData
}).done(function (data) {
self.user = data.userName;
// Cache the access token in session storage.
sessionStorage.setItem(tokenKey, data.access_token);
}).fail(showError);
}
How can I prevent access to a group of HTML pages, such that the user has to have a valid token or logon details before a page is loaded?
Can javaScript be used successfully with a simple cookie or sessionStorage check?