-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathfusionAuth.js
53 lines (45 loc) · 1.78 KB
/
fusionAuth.js
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
(function() {
let encode = encodeURIComponent;
window.FusionAuth = {
schemas: "",
windowTarget: "_blank",
windowFeatures: "width=600,height=600",
signInPath: "/signIn",
signOutPath: "/signOut",
closePath: "/fusion/close",
enablePopup: true,
mustRedirectOnPopupBlock: true,
signIn: function(schema) {
if (schema === undefined || schema === null || schema === "") {
this.authPopupOrRedirect(this.signInPath, "Sign-in");
} else {
this.authPopupOrRedirect(this.signInPath + "/" + schema, "Sign-in");
}
},
signOut: function() {
this.authPopupOrRedirect(this.signOutPath, "Sign-out");
},
authPopupOrRedirect: function(action, flowName) {
if (!this.enablePopup) {
this.authRedirect(action);
return;
}
let redirectUrl = new URL(this.closePath +"?flow=" + encode(flowName), document.baseURI).href;
let url = action + "?returnUrl=" + encode(redirectUrl);
let popup = window.open(url, FusionAuth.windowTarget, FusionAuth.windowFeatures);
if (!popup || popup.closed || typeof popup.closed == 'undefined') {
if (this.mustRedirectOnPopupBlock) {
this.authRedirect(action);
}
else {
alert("Authentication popup is blocked by the browser. Please allow popups on this website and retry.")
}
}
},
authRedirect(action) {
let redirectUrl = window.location.href;
let url = action + "?returnUrl=" + encode(redirectUrl);
window.location.replace(url);
}
};
})();