saasufy-components 9.5.2 → 9.6.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.
- package/README.md +3 -0
- package/oauth-handler.js +14 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -972,6 +972,8 @@ A link to initiate an OAuth flow to authenticate a user as part of log in. Can s
|
|
|
972
972
|
|
|
973
973
|
- `provider` (required): The name of the provider. It must match the provider name specified on the `Authentication` page of your Saasufy control panel and also the value provided to the `oauth-handler` component at the end of the OAuth flow.
|
|
974
974
|
- `client-id` (required): This is the client ID from the third-party OAuth provider.
|
|
975
|
+
- `redirect-uri`: A URI to redirect the user to once OAuth is successful. This attribute may be required depending on the OAuth provider/client.
|
|
976
|
+
- `grant-type`: The grant type for this OAuth flow. Typically set to `authorization_code`. This may be required depending on the OAuth provider/client.
|
|
975
977
|
- `state-size`: This allows you to control the size (in bytes) of the random state string which is passed to the OAuth provider as part of the OAuth flow. Defaults to 20.
|
|
976
978
|
- `state-storage-key`: The state string is stored in the browser's `sessionStorage` under this key. Defaults to `oauth.state`. It must match the value provided to the `oauth-handler` component at the end of the OAuth flow.
|
|
977
979
|
- `use-session-storage`: By default, the state is stored inside localStorage. If this property is set, then the state will be stored inside sessionStorage instead. If set, this attribute should also be set on the related `oauth-handler` component.
|
|
@@ -998,6 +1000,7 @@ When using an OAuth provider, the callback URL which you register with the provi
|
|
|
998
1000
|
- `provider` (required): The name of the provider. It must match the provider name specified on the `Authentication` page of your Saasufy control panel and also the value provided to the `oauth-link` component at the start of the OAuth flow.
|
|
999
1001
|
- `success-location-hash`: If authentication is successful, the browser's `location.hash` will be set to this value. It can be used to redirect the user to their dashboard, for example.
|
|
1000
1002
|
- `success-url`: If authentication is successful, the browser's `location.href` will be set to this value. It can be used to redirect the user to their dashboard, for example.
|
|
1003
|
+
- `redirect-uri`: A URI to redirect the user to once OAuth is successful. This attribute may be required depending on the OAuth provider/client.
|
|
1001
1004
|
- `extra-data`: This attribute can be used to pass additional data to the OAuth `getAccessTokenURL` endpoint. For Google OAuth, for example, an additional `redirect_uri` field is required, so it should be set using `extra-data="redirect_uri=http://localhost.com:8000/"` (substitute the URI with your own).
|
|
1002
1005
|
- `navigate-event-path`: If authentication is successful and a path is set via this attribute, the component will emit a `navigate` event which will bubble up the component hierarchy and can be used by a parent component to perform the success redirection. This approach can be used as an alternative to `success-location-hash` or `success-url` for doing the final redirect.
|
|
1003
1006
|
- `state-storage-key`: The state string is stored in the browser's `sessionStorage` under this key. Defaults to `oauth.state`. It must match the value provided to the `oauth-link` component at the start of the OAuth flow.
|
package/oauth-handler.js
CHANGED
|
@@ -25,6 +25,13 @@ class OAuthHandler extends SocketConsumer {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
getProviderFromState(state) {
|
|
29
|
+
if (typeof state !== 'string') return '';
|
|
30
|
+
let lastDashIndex = state.lastIndexOf('-');
|
|
31
|
+
if (lastDashIndex === -1) return state;
|
|
32
|
+
return state.slice(0, lastDashIndex);
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
async connectedCallback() {
|
|
29
36
|
this.innerHTML = '';
|
|
30
37
|
|
|
@@ -45,7 +52,7 @@ class OAuthHandler extends SocketConsumer {
|
|
|
45
52
|
|
|
46
53
|
let relevantStates = expectedOAuthState
|
|
47
54
|
.split(',')
|
|
48
|
-
.filter(expectedState =>
|
|
55
|
+
.filter(expectedState => this.getProviderFromState(expectedState) === provider);
|
|
49
56
|
|
|
50
57
|
// Do not process. The state may have been set for a different provider
|
|
51
58
|
// which is handled on the same page.
|
|
@@ -55,12 +62,17 @@ class OAuthHandler extends SocketConsumer {
|
|
|
55
62
|
let stateParamName = this.getAttribute('state-param-name') || 'state';
|
|
56
63
|
let extraDataString = this.getAttribute('extra-data') || '';
|
|
57
64
|
let { fieldValues: extraData } = convertStringToFieldParams(extraDataString);
|
|
65
|
+
let redirectURI = this.getAttribute('redirect-uri');
|
|
66
|
+
|
|
67
|
+
if (redirectURI) {
|
|
68
|
+
extraData.redirectURI = redirectURI;
|
|
69
|
+
}
|
|
58
70
|
|
|
59
71
|
let authTimeout = Number(this.getAttribute('auth-timeout') || DEFAULT_AUTH_TIMEOUT);
|
|
60
72
|
let urlSearchParams = new URLSearchParams(location.search);
|
|
61
73
|
let state = urlSearchParams.get(stateParamName);
|
|
62
74
|
|
|
63
|
-
let stateProvider = (state
|
|
75
|
+
let stateProvider = this.getProviderFromState(state);
|
|
64
76
|
if (stateProvider !== provider) return;
|
|
65
77
|
|
|
66
78
|
let code = urlSearchParams.get(codeParamName);
|