-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthentication.js
More file actions
79 lines (67 loc) · 3.05 KB
/
Authentication.js
File metadata and controls
79 lines (67 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
if(!javaxt) var javaxt={};
if(!javaxt.dhtml) javaxt.dhtml={};
//******************************************************************************
//** Http Authentication
//*****************************************************************************/
/**
* Used to perform BASIC HTTP authentication
*
******************************************************************************/
javaxt.dhtml.Authentication = function(loginURL, logoutURL) {
var userAgent = navigator.userAgent.toLowerCase();
//**************************************************************************
//** login
//*************************************************************************/
/** Used to execute an http get request to login a user.
*/
this.login = function(username, password, callback){
var logoff = this.logoff;
//Instantiate HTTP Request
var request = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
request.open("GET", loginURL, true, username, password);
request.setRequestHeader("Cache-Control", "no-cache, no-transform");
request.onreadystatechange = function(){
if (request.readyState === 4) {
if (request.status !== 200){
if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1){
logoff();
}
}
if (callback!=null) callback.call(request);
}
};
request.send(null);
};
//**************************************************************************
//** logoff
//*************************************************************************/
/** Used to execute an http get request to clear the http auth.
*/
this.logoff = function(callback){
if (userAgent.indexOf("msie") != -1) {
document.execCommand("ClearAuthenticationCache");
if (callback!=null) callback.call();
}
else{
//Logout. Tell the server not to return the "WWW-Authenticate" header
var request = new XMLHttpRequest();
request.open("GET", logoutURL + "?prompt=false", true);
request.setRequestHeader("Cache-Control", "no-cache, no-transform");
request.onreadystatechange = function(){
if (request.readyState === 4) {
//Login with dummy credentials to clear the auth cache
var request2 = new XMLHttpRequest();
request2.open("GET", loginURL, true, "logout", "logout");
request2.setRequestHeader("Cache-Control", "no-cache, no-transform");
request2.onreadystatechange = function(){
if (request2.readyState === 4) {
if (callback!=null) callback.call();
}
};
request2.send("");
}
};
request.send("");
}
};
};