@oneidentity/safeguard 1.0.5 → 7.4.0

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.
@@ -40,5 +40,92 @@ const SafeguardJsAccessTokenChecker = {
40
40
  }
41
41
  }
42
42
 
43
+ /**
44
+ * SafeguardJsCodeStateChecker
45
+ *
46
+ * This is used to check for incoming pkce code and state from Rsts. Upon successful authentication
47
+ * with Rsts, Rsts will redirect to a given page with the code as a parameter. That page
48
+ * needs to have this accessTokenCheck.js file so that the code can be identified, and stored in
49
+ * the appropriate storage location.
50
+ *
51
+ * By default this uses the SafeguardJs.Storage class. If a custom Storage class has been implemented,
52
+ * the check method should be called with the appropriate storage object instead.
53
+ */
54
+ const SafeguardJsCodeStateChecker = {
55
+ /**
56
+ * Gets the code from the parameters.
57
+ */
58
+ getCode() {
59
+ var index = window.location.href.indexOf("code=");
60
+ if (index == -1){
61
+ return null;
62
+ }
63
+ var token = window.location.href.substring(index+5);
64
+ var eindex = token.search(/[&#\/]/);
65
+ if (eindex > -1){
66
+ return token.substring(0, eindex);
67
+ }
68
+ return token;
69
+ },
70
+ /**
71
+ * Gets the state from the parameters.
72
+ */
73
+ getState() {
74
+ var index = window.location.href.indexOf("state=");
75
+ if (index == -1){
76
+ return null;
77
+ }
78
+ var token = window.location.href.substring(index+6);
79
+ var eindex = token.search(/[&#\/]/);
80
+ if (eindex > -1){
81
+ return token.substring(0, eindex);
82
+ }
83
+ return token;
84
+ },
85
+
86
+ /**
87
+ * Checks for and stores a code and state in the provided storage location. The page is then redirected
88
+ * to itself omitting the access token parameter.
89
+ * @param {SafeguardJs.Storage} storage The storage location the access token should be saved to.
90
+ */
91
+ check(storage) {
92
+ var code = this.getCode();
93
+ var state = this.getState();
94
+ if (code && state) {
95
+ storage.setCode(code);
96
+ storage.setState(state);
97
+ window.location.href = `${window.location.protocol}//${window.location.host}${window.location.pathname}`;
98
+ }
99
+ }
100
+ }
101
+
102
+ /**
103
+ * SafeguardJsNewLoginChecker
104
+ *
105
+ * This is used to check for incoming new login. Upon successful authentication
106
+ * with Rsts, Rsts will redirect to a given page with the access token as a parameter. That page
107
+ * needs to have this accessTokenCheck.js file so that the token can be identified, and stored in
108
+ * the appropriate storage location.
109
+ *
110
+ * By default this uses the SafeguardJs.Storage class. If a custom Storage class has been implemented,
111
+ * the check method should be called with the appropriate storage object instead.
112
+ */
113
+ const SafeguardJsNewLoginChecker = {
114
+ /**
115
+ * Checks for and stores an access token in the provided storage location. The page is then redirected
116
+ * to itself omitting the access token parameter.
117
+ * @param {SafeguardJs.Storage} storage The storage location the access token should be saved to.
118
+ */
119
+ check(storage) {
120
+ if (window.location.href.toLowerCase().indexOf("?newlogin") > -1) {
121
+ storage.setNewLogin(true);
122
+ }
123
+ }
124
+ }
125
+
43
126
  // Perform the access token check whenever the script is loaded.
44
127
  SafeguardJsAccessTokenChecker.check(SafeguardJs.Storage);
128
+ // Perform the code and state check whenever the script is loaded.
129
+ SafeguardJsCodeStateChecker.check(SafeguardJs.Storage);
130
+ // Perform the new login check whenever the script is loaded.
131
+ SafeguardJsNewLoginChecker.check(SafeguardJs.Storage);
@@ -1 +1 @@
1
- const o={getAccessToken(){var o=window.location.href.indexOf("access_token=");if(-1==o)return null;var n=window.location.href.substring(o+13),o=n.search(/[&#\/]/);return-1<o?n.substring(0,o):n},check(o){var n=this.getAccessToken();n&&(o.setAccessToken(n),window.location.href=`${window.location.protocol}//${window.location.host}${window.location.pathname}`)}};o.check(SafeguardJs.Storage);
1
+ var o={getCode(){var o,e=window.location.href.indexOf("code=");return-1==e?null:-1<(o=(e=window.location.href.substring(e+5)).search(/[&#\/]/))?e.substring(0,o):e},getState(){var o,e=window.location.href.indexOf("state=");return-1==e?null:-1<(o=(e=window.location.href.substring(e+6)).search(/[&#\/]/))?e.substring(0,o):e},check(o){var e=this.getCode(),n=this.getState();e&&n&&(o.setCode(e),o.setState(n),window.location.href=window.location.protocol+"//"+window.location.host+window.location.pathname)}};const e=function(o){-1<window.location.href.toLowerCase().indexOf("?newlogin")&&o.setNewLogin(!0)};({getAccessToken(){var o,e=window.location.href.indexOf("access_token=");return-1==e?null:-1<(o=(e=window.location.href.substring(e+13)).search(/[&#\/]/))?e.substring(0,o):e},check(o){var e=this.getAccessToken();e&&(o.setAccessToken(e),window.location.href=window.location.protocol+"//"+window.location.host+window.location.pathname)}}).check(SafeguardJs.Storage),o.check(SafeguardJs.Storage),e(SafeguardJs.Storage);