saasufy-components 3.22.0 → 3.23.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 +1 -0
- package/oauth-handler.js +4 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -811,6 +811,7 @@ When using an OAuth provider, the callback URL which you register with the provi
|
|
|
811
811
|
- `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.
|
|
812
812
|
- `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.
|
|
813
813
|
- `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.
|
|
814
|
+
- `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).
|
|
814
815
|
- `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.
|
|
815
816
|
- `state-session-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.
|
|
816
817
|
- `code-param-name`: The name of the query parameter which holds the `code` as provided by the OAuth provider within the OAuth callback URL. Defaults to `code`.
|
package/oauth-handler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SocketConsumer } from './socket.js';
|
|
2
|
-
import { generateRandomHexString } from './utils.js';
|
|
2
|
+
import { generateRandomHexString, convertStringToFieldParams } from './utils.js';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_AUTH_TIMEOUT = 10000;
|
|
5
5
|
|
|
@@ -49,9 +49,10 @@ class OAuthHandler extends SocketConsumer {
|
|
|
49
49
|
|
|
50
50
|
let codeParamName = this.getAttribute('code-param-name') || 'code';
|
|
51
51
|
let stateParamName = this.getAttribute('state-param-name') || 'state';
|
|
52
|
+
let extraDataString = this.getAttribute('extra-data') || '';
|
|
53
|
+
let { fieldValues: extraData } = convertStringToFieldParams(extraDataString);
|
|
52
54
|
|
|
53
55
|
let authTimeout = Number(this.getAttribute('auth-timeout') || DEFAULT_AUTH_TIMEOUT);
|
|
54
|
-
|
|
55
56
|
let urlSearchParams = new URLSearchParams(location.search);
|
|
56
57
|
let code = urlSearchParams.get(codeParamName);
|
|
57
58
|
|
|
@@ -63,7 +64,7 @@ class OAuthHandler extends SocketConsumer {
|
|
|
63
64
|
|
|
64
65
|
if (state === expectedOAuthState) {
|
|
65
66
|
try {
|
|
66
|
-
await socket.invoke('log-in-oauth', { provider, data: { code } });
|
|
67
|
+
await socket.invoke('log-in-oauth', { provider, data: { code, ...extraData } });
|
|
67
68
|
} catch (error) {
|
|
68
69
|
this.innerHTML = `
|
|
69
70
|
<div class="error">OAuth authentication failed. ${error.message}</div>
|