saasufy-components 8.2.0 → 8.2.1
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/oauth-handler.js +7 -4
- package/oauth-link.js +16 -1
- package/package.json +1 -1
package/oauth-handler.js
CHANGED
|
@@ -43,10 +43,13 @@ class OAuthHandler extends SocketConsumer {
|
|
|
43
43
|
return;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
let
|
|
46
|
+
let relevantStates = expectedOAuthState
|
|
47
|
+
.split(',')
|
|
48
|
+
.filter(expectedState => expectedState && expectedState.split('-')[0] === provider);
|
|
49
|
+
|
|
47
50
|
// Do not process. The state may have been set for a different provider
|
|
48
51
|
// which is handled on the same page.
|
|
49
|
-
if (
|
|
52
|
+
if (!relevantStates.length) return;
|
|
50
53
|
|
|
51
54
|
let codeParamName = this.getAttribute('code-param-name') || 'code';
|
|
52
55
|
let stateParamName = this.getAttribute('state-param-name') || 'state';
|
|
@@ -62,8 +65,8 @@ class OAuthHandler extends SocketConsumer {
|
|
|
62
65
|
let socket = this.getSocket();
|
|
63
66
|
|
|
64
67
|
history.replaceState({}, document.title, location.pathname);
|
|
65
|
-
|
|
66
|
-
if (
|
|
68
|
+
|
|
69
|
+
if (relevantStates.some(expectedState => expectedState === state)) {
|
|
67
70
|
try {
|
|
68
71
|
await socket.invoke('log-in-oauth', { provider, data: { code, ...extraData } });
|
|
69
72
|
} catch (error) {
|
package/oauth-link.js
CHANGED
|
@@ -75,8 +75,23 @@ class OAuthLink extends HTMLElement {
|
|
|
75
75
|
let useLocalStorage = this.hasAttribute('use-local-storage');
|
|
76
76
|
let stateSize = Number(this.getAttribute('state-size') || 20);
|
|
77
77
|
let storageKey = this.getAttribute('state-storage-key') || 'oauth.state';
|
|
78
|
+
|
|
79
|
+
let storage = useLocalStorage ? localStorage : sessionStorage;
|
|
80
|
+
let existingState = storage.getItem(storageKey);
|
|
81
|
+
let stateList;
|
|
82
|
+
if (existingState) {
|
|
83
|
+
stateList = existingState.split(',').filter(Boolean);
|
|
84
|
+
let maxStateCount = Number(this.getAttribute('max-state-count') ?? 20);
|
|
85
|
+
if (stateList.length >= maxStateCount) {
|
|
86
|
+
stateList.pop();
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
stateList = []
|
|
90
|
+
}
|
|
78
91
|
this.state = `${provider}-${generateRandomHexString(stateSize)}`;
|
|
79
|
-
|
|
92
|
+
stateList.unshift(this.state);
|
|
93
|
+
|
|
94
|
+
storage.setItem(storageKey, stateList.join(','));
|
|
80
95
|
|
|
81
96
|
this.shadowRoot.innerHTML = `
|
|
82
97
|
<slot name="item"></slot>
|