@authsignal/browser 0.0.6 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/index.js +99 -27
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +99 -28
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts +55 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Authsignal Browser Javascript SDK
|
|
2
2
|
|
|
3
|
-
**[Authsignal](https://www.authsignal.com) provides passwordless step up authentication (Multi-factor Authentication - MFA) that can be placed anywhere within your application. Authsignal also provides a
|
|
3
|
+
**[Authsignal](https://www.authsignal.com) provides passwordless step up authentication (Multi-factor Authentication - MFA) that can be placed anywhere within your application. Authsignal also provides a no-code fraud risk rules engine to manage when step up challenges are triggered.**
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
## Usage
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,6 +2,37 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Copyright (c) Microsoft Corporation.
|
|
7
|
+
|
|
8
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
9
|
+
purpose with or without fee is hereby granted.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
12
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
13
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
14
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
15
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
16
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
17
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
***************************************************************************** */
|
|
19
|
+
/* global Reflect, Promise */
|
|
20
|
+
|
|
21
|
+
var extendStatics = function(d, b) {
|
|
22
|
+
extendStatics = Object.setPrototypeOf ||
|
|
23
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
24
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
25
|
+
return extendStatics(d, b);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function __extends(d, b) {
|
|
29
|
+
if (typeof b !== "function" && b !== null)
|
|
30
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
31
|
+
extendStatics(d, b);
|
|
32
|
+
function __() { this.constructor = d; }
|
|
33
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
34
|
+
}
|
|
35
|
+
|
|
5
36
|
// Unique ID creation requires a high quality random # generator. In the browser we therefore
|
|
6
37
|
// require the crypto API and do not support built-in fallback to lower quality random number
|
|
7
38
|
// generators (like Math.random()).
|
|
@@ -505,6 +536,11 @@ var getCookie = function (name) {
|
|
|
505
536
|
return (decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(name).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null);
|
|
506
537
|
};
|
|
507
538
|
|
|
539
|
+
exports.AuthsignalWindowMessage = void 0;
|
|
540
|
+
(function (AuthsignalWindowMessage) {
|
|
541
|
+
AuthsignalWindowMessage["AUTHSIGNAL_CLOSE_POPUP"] = "AUTHSIGNAL_CLOSE_POPUP";
|
|
542
|
+
})(exports.AuthsignalWindowMessage || (exports.AuthsignalWindowMessage = {}));
|
|
543
|
+
|
|
508
544
|
var focusableSelectors = [
|
|
509
545
|
'a[href]:not([tabindex^="-"])',
|
|
510
546
|
'area[href]:not([tabindex^="-"])',
|
|
@@ -908,6 +944,7 @@ var PopupHandler = /** @class */ (function () {
|
|
|
908
944
|
this.create();
|
|
909
945
|
}
|
|
910
946
|
PopupHandler.prototype.create = function () {
|
|
947
|
+
var _this = this;
|
|
911
948
|
// Create dialog container
|
|
912
949
|
var container = document.createElement("div");
|
|
913
950
|
container.setAttribute("id", CONTAINER_ID);
|
|
@@ -923,13 +960,16 @@ var PopupHandler = /** @class */ (function () {
|
|
|
923
960
|
// Create CSS for dialog
|
|
924
961
|
var style = document.createElement("style");
|
|
925
962
|
style.setAttribute("id", STYLE_ID);
|
|
926
|
-
style.textContent = "\n #".concat(CONTAINER_ID, ",\n #").concat(OVERLAY_ID, " {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(CONTAINER_ID, " {\n z-index:
|
|
963
|
+
style.textContent = "\n #".concat(CONTAINER_ID, ",\n #").concat(OVERLAY_ID, " {\n position: fixed;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n }\n\n #").concat(CONTAINER_ID, " {\n z-index: 2147483647;\n display: flex;\n }\n\n #").concat(CONTAINER_ID, "[aria-hidden='true'] {\n display: none;\n }\n\n #").concat(OVERLAY_ID, " {\n background-color: rgba(43, 46, 56, 0.9);\n }\n\n #").concat(CONTENT_ID, " {\n margin: auto;\n z-index: 2147483647;\n position: relative;\n background-color: white;\n height: 600px;\n width: 600px;\n border-radius: 5px;\n }\n\n #").concat(CONTENT_ID, " iframe {\n width: 100%;\n height: 100%;\n }\n ");
|
|
927
964
|
// Attach the created elements
|
|
928
965
|
document.head.insertAdjacentElement("beforeend", style);
|
|
929
966
|
container.appendChild(overlay);
|
|
930
967
|
container.appendChild(content);
|
|
931
968
|
this.popup = new A11yDialog(container);
|
|
932
|
-
|
|
969
|
+
// Make sure to remove any trace of the dialog on hide
|
|
970
|
+
this.popup.on("hide", function () {
|
|
971
|
+
_this.destroy();
|
|
972
|
+
});
|
|
933
973
|
};
|
|
934
974
|
PopupHandler.prototype.destroy = function () {
|
|
935
975
|
var dialogEl = document.querySelector("#".concat(CONTAINER_ID));
|
|
@@ -940,14 +980,14 @@ var PopupHandler = /** @class */ (function () {
|
|
|
940
980
|
}
|
|
941
981
|
};
|
|
942
982
|
PopupHandler.prototype.show = function (_a) {
|
|
943
|
-
var
|
|
983
|
+
var url = _a.url;
|
|
944
984
|
if (!this.popup) {
|
|
945
985
|
throw new Error("Popup is not initialized");
|
|
946
986
|
}
|
|
947
987
|
var iframe = document.createElement("iframe");
|
|
948
988
|
iframe.setAttribute("name", "authsignal");
|
|
949
|
-
iframe.setAttribute("title", "Authsignal multi-factor authentication
|
|
950
|
-
iframe.setAttribute("src",
|
|
989
|
+
iframe.setAttribute("title", "Authsignal multi-factor authentication");
|
|
990
|
+
iframe.setAttribute("src", url);
|
|
951
991
|
iframe.setAttribute("frameborder", "0");
|
|
952
992
|
var dialogContent = document.querySelector("#".concat(CONTENT_ID));
|
|
953
993
|
if (dialogContent) {
|
|
@@ -961,19 +1001,29 @@ var PopupHandler = /** @class */ (function () {
|
|
|
961
1001
|
}
|
|
962
1002
|
this.popup.hide();
|
|
963
1003
|
};
|
|
1004
|
+
PopupHandler.prototype.on = function (event, handler) {
|
|
1005
|
+
if (!this.popup) {
|
|
1006
|
+
throw new Error("Popup is not initialized");
|
|
1007
|
+
}
|
|
1008
|
+
this.popup.on(event, handler);
|
|
1009
|
+
};
|
|
964
1010
|
return PopupHandler;
|
|
965
1011
|
}());
|
|
966
1012
|
|
|
967
|
-
var
|
|
968
|
-
|
|
969
|
-
|
|
1013
|
+
var DEFAULT_ENDPOINT = "https://mfa.authsignal.com/";
|
|
1014
|
+
var DEFAULT_COOKIE_NAME = "__as_aid";
|
|
1015
|
+
var Authsignal = /** @class */ (function () {
|
|
1016
|
+
function Authsignal(_a) {
|
|
1017
|
+
var publishableKey = _a.publishableKey, cookieDomain = _a.cookieDomain, cookieName = _a.cookieName, endpoint = _a.endpoint;
|
|
970
1018
|
this.anonymousId = "";
|
|
971
1019
|
this.cookieDomain = "";
|
|
972
1020
|
this.anonymousIdCookieName = "";
|
|
973
1021
|
this.publishableKey = "";
|
|
1022
|
+
this.endpoint = "";
|
|
974
1023
|
this.publishableKey = publishableKey;
|
|
975
1024
|
this.cookieDomain = cookieDomain || getCookieDomain();
|
|
976
|
-
this.anonymousIdCookieName = cookieName ||
|
|
1025
|
+
this.anonymousIdCookieName = cookieName || DEFAULT_COOKIE_NAME;
|
|
1026
|
+
this.endpoint = endpoint || DEFAULT_ENDPOINT;
|
|
977
1027
|
var idCookie = getCookie(this.anonymousIdCookieName);
|
|
978
1028
|
if (!idCookie) {
|
|
979
1029
|
this.anonymousId = v4();
|
|
@@ -986,35 +1036,57 @@ var AuthsignalBrowser = /** @class */ (function () {
|
|
|
986
1036
|
});
|
|
987
1037
|
}
|
|
988
1038
|
}
|
|
989
|
-
|
|
990
|
-
var url = _a.url;
|
|
991
|
-
|
|
1039
|
+
Authsignal.prototype.mfa = function (_a) {
|
|
1040
|
+
var mode = _a.mode, url = _a.url;
|
|
1041
|
+
if (mode === "popup") {
|
|
1042
|
+
return this.launch(url, { mode: mode });
|
|
1043
|
+
}
|
|
1044
|
+
return this.launch(url, { mode: mode });
|
|
1045
|
+
};
|
|
1046
|
+
Authsignal.prototype.challenge = function (_a) {
|
|
1047
|
+
var mode = _a.mode, url = _a.challengeUrl;
|
|
1048
|
+
if (mode === "popup") {
|
|
1049
|
+
return this.launch(url, { mode: mode });
|
|
1050
|
+
}
|
|
1051
|
+
return this.launch(url, { mode: mode });
|
|
992
1052
|
};
|
|
993
|
-
|
|
994
|
-
var
|
|
1053
|
+
Authsignal.prototype.launch = function (url, options) {
|
|
1054
|
+
var _this = this;
|
|
1055
|
+
var mode = (options === null || options === void 0 ? void 0 : options.mode) || "redirect";
|
|
995
1056
|
if (mode === "redirect") {
|
|
996
|
-
window.location.href =
|
|
1057
|
+
window.location.href = url;
|
|
997
1058
|
}
|
|
998
1059
|
else {
|
|
999
1060
|
var Popup_1 = new PopupHandler();
|
|
1000
|
-
Popup_1.show({
|
|
1001
|
-
return new Promise(function (resolve
|
|
1002
|
-
var
|
|
1003
|
-
if (event.
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
else if (event.data === "authsignal-challenge-failure") {
|
|
1008
|
-
Popup_1.close();
|
|
1009
|
-
reject(false);
|
|
1061
|
+
Popup_1.show({ url: url });
|
|
1062
|
+
return new Promise(function (resolve) {
|
|
1063
|
+
var onMessage = function (event) {
|
|
1064
|
+
if (event.origin === _this.endpoint) {
|
|
1065
|
+
if (event.data === exports.AuthsignalWindowMessage.AUTHSIGNAL_CLOSE_POPUP) {
|
|
1066
|
+
Popup_1.close();
|
|
1067
|
+
}
|
|
1010
1068
|
}
|
|
1011
1069
|
};
|
|
1012
|
-
|
|
1070
|
+
Popup_1.on("hide", function () {
|
|
1071
|
+
resolve(true);
|
|
1072
|
+
});
|
|
1073
|
+
window.addEventListener("message", onMessage, false);
|
|
1013
1074
|
});
|
|
1014
1075
|
}
|
|
1015
1076
|
};
|
|
1016
|
-
return
|
|
1077
|
+
return Authsignal;
|
|
1017
1078
|
}());
|
|
1079
|
+
/**
|
|
1080
|
+
* @deprecated Use Authsignal
|
|
1081
|
+
*/
|
|
1082
|
+
var AuthsignalBrowser = /** @class */ (function (_super) {
|
|
1083
|
+
__extends(AuthsignalBrowser, _super);
|
|
1084
|
+
function AuthsignalBrowser() {
|
|
1085
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
1086
|
+
}
|
|
1087
|
+
return AuthsignalBrowser;
|
|
1088
|
+
}(Authsignal));
|
|
1018
1089
|
|
|
1090
|
+
exports.Authsignal = Authsignal;
|
|
1019
1091
|
exports.AuthsignalBrowser = AuthsignalBrowser;
|
|
1020
1092
|
//# sourceMappingURL=index.js.map
|