@wix/sdk 1.21.2 → 1.21.3
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/build/auth/oauth2/OAuthStrategy.d.ts +7 -1
- package/build/auth/oauth2/OAuthStrategy.js +10 -3
- package/build/auth/oauth2/types.d.ts +10 -0
- package/cjs/build/auth/oauth2/OAuthStrategy.d.ts +7 -1
- package/cjs/build/auth/oauth2/OAuthStrategy.js +10 -3
- package/cjs/build/auth/oauth2/types.d.ts +10 -0
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
1
|
+
import { IOAuthStrategy, TokenRequestOptions, Tokens, TokenStorage } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* OAuth authentication strategy for Wix SDK.
|
|
4
4
|
* @param config - Configuration object
|
|
@@ -8,6 +8,8 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
8
8
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
9
9
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
10
10
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
11
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
12
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
11
13
|
* @returns OAuth strategy instance
|
|
12
14
|
* @example
|
|
13
15
|
* // Default in-memory storage with initial tokens
|
|
@@ -15,10 +17,14 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
15
17
|
* @example
|
|
16
18
|
* // Custom storage (e.g., cookies)
|
|
17
19
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
20
|
+
* @example
|
|
21
|
+
* // With custom headers for all token requests
|
|
22
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
18
23
|
*/
|
|
19
24
|
export declare function OAuthStrategy(config: {
|
|
20
25
|
clientId: string;
|
|
21
26
|
publicKey?: string;
|
|
27
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
22
28
|
} & ({
|
|
23
29
|
tokens?: Tokens;
|
|
24
30
|
tokenStorage?: never;
|
|
@@ -20,6 +20,8 @@ const moduleWithTokens = { redirects, authentication, recovery, verification };
|
|
|
20
20
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
21
21
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
22
22
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
23
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
24
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
23
25
|
* @returns OAuth strategy instance
|
|
24
26
|
* @example
|
|
25
27
|
* // Default in-memory storage with initial tokens
|
|
@@ -27,8 +29,12 @@ const moduleWithTokens = { redirects, authentication, recovery, verification };
|
|
|
27
29
|
* @example
|
|
28
30
|
* // Custom storage (e.g., cookies)
|
|
29
31
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
32
|
+
* @example
|
|
33
|
+
* // With custom headers for all token requests
|
|
34
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
30
35
|
*/
|
|
31
36
|
export function OAuthStrategy(config) {
|
|
37
|
+
const _tokenRequestHeaders = config.tokenRequestOptions?.headers ?? {};
|
|
32
38
|
const _tokenStorage = config.tokenStorage ??
|
|
33
39
|
createLocalTokenStorage(config.tokens ?? EMPTY_TOKENS);
|
|
34
40
|
const getTokens = () => _tokenStorage.getTokens();
|
|
@@ -81,7 +87,7 @@ export function OAuthStrategy(config) {
|
|
|
81
87
|
const tokensResponse = await fetchTokens({
|
|
82
88
|
clientId: config.clientId,
|
|
83
89
|
grantType: 'anonymous',
|
|
84
|
-
});
|
|
90
|
+
}, _tokenRequestHeaders);
|
|
85
91
|
return {
|
|
86
92
|
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
87
93
|
refreshToken: {
|
|
@@ -94,7 +100,7 @@ export function OAuthStrategy(config) {
|
|
|
94
100
|
const tokensResponse = await fetchTokens({
|
|
95
101
|
refreshToken: refreshToken.value,
|
|
96
102
|
grantType: 'refresh_token',
|
|
97
|
-
});
|
|
103
|
+
}, _tokenRequestHeaders);
|
|
98
104
|
const accessToken = createAccessToken(tokensResponse.access_token, tokensResponse.expires_in);
|
|
99
105
|
return {
|
|
100
106
|
accessToken,
|
|
@@ -175,7 +181,7 @@ export function OAuthStrategy(config) {
|
|
|
175
181
|
...(oauthData.redirectUri && { redirectUri: oauthData.redirectUri }),
|
|
176
182
|
code,
|
|
177
183
|
codeVerifier: oauthData.codeVerifier,
|
|
178
|
-
});
|
|
184
|
+
}, _tokenRequestHeaders);
|
|
179
185
|
return {
|
|
180
186
|
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
181
187
|
refreshToken: {
|
|
@@ -350,6 +356,7 @@ export function OAuthStrategy(config) {
|
|
|
350
356
|
member_id: memberId,
|
|
351
357
|
}, {
|
|
352
358
|
Authorization: getTokens().accessToken.value + ',' + apiKey,
|
|
359
|
+
..._tokenRequestHeaders,
|
|
353
360
|
});
|
|
354
361
|
return {
|
|
355
362
|
accessToken: createAccessToken(tokensResponse.access_token, tokensResponse.expires_in),
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { authentication } from '@wix/identity';
|
|
2
2
|
import { AuthenticationStrategy } from '@wix/sdk-types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for token-related API requests.
|
|
5
|
+
*/
|
|
6
|
+
export interface TokenRequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Custom headers to include in the token request.
|
|
9
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
10
|
+
*/
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
3
13
|
export interface Tokens {
|
|
4
14
|
accessToken: AccessToken;
|
|
5
15
|
refreshToken: RefreshToken;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
1
|
+
import { IOAuthStrategy, TokenRequestOptions, Tokens, TokenStorage } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* OAuth authentication strategy for Wix SDK.
|
|
4
4
|
* @param config - Configuration object
|
|
@@ -8,6 +8,8 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
8
8
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
9
9
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
10
10
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
11
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
12
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
11
13
|
* @returns OAuth strategy instance
|
|
12
14
|
* @example
|
|
13
15
|
* // Default in-memory storage with initial tokens
|
|
@@ -15,10 +17,14 @@ import { IOAuthStrategy, Tokens, TokenStorage } from './types.js';
|
|
|
15
17
|
* @example
|
|
16
18
|
* // Custom storage (e.g., cookies)
|
|
17
19
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
20
|
+
* @example
|
|
21
|
+
* // With custom headers for all token requests
|
|
22
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
18
23
|
*/
|
|
19
24
|
export declare function OAuthStrategy(config: {
|
|
20
25
|
clientId: string;
|
|
21
26
|
publicKey?: string;
|
|
27
|
+
tokenRequestOptions?: TokenRequestOptions;
|
|
22
28
|
} & ({
|
|
23
29
|
tokens?: Tokens;
|
|
24
30
|
tokenStorage?: never;
|
|
@@ -23,6 +23,8 @@ const moduleWithTokens = { redirects: redirects_1.redirects, authentication: ide
|
|
|
23
23
|
* @param config.tokenStorage - Custom storage implementation (mutually exclusive with `tokens`).
|
|
24
24
|
* When provided, the strategy delegates all token persistence to this storage.
|
|
25
25
|
* The storage's `getTokens()` must always return `Tokens` (use `EMPTY_TOKENS` as fallback).
|
|
26
|
+
* @param config.tokenRequestOptions - Optional request options (e.g., custom headers) for all token requests.
|
|
27
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
26
28
|
* @returns OAuth strategy instance
|
|
27
29
|
* @example
|
|
28
30
|
* // Default in-memory storage with initial tokens
|
|
@@ -30,8 +32,12 @@ const moduleWithTokens = { redirects: redirects_1.redirects, authentication: ide
|
|
|
30
32
|
* @example
|
|
31
33
|
* // Custom storage (e.g., cookies)
|
|
32
34
|
* OAuthStrategy({ clientId: 'xxx', tokenStorage: myCookieStorage })
|
|
35
|
+
* @example
|
|
36
|
+
* // With custom headers for all token requests
|
|
37
|
+
* OAuthStrategy({ clientId: 'xxx', tokenRequestOptions: { headers: { 'client-binding': '...' } } })
|
|
33
38
|
*/
|
|
34
39
|
function OAuthStrategy(config) {
|
|
40
|
+
const _tokenRequestHeaders = config.tokenRequestOptions?.headers ?? {};
|
|
35
41
|
const _tokenStorage = config.tokenStorage ??
|
|
36
42
|
(0, token_storage_js_1.createLocalTokenStorage)(config.tokens ?? token_storage_js_1.EMPTY_TOKENS);
|
|
37
43
|
const getTokens = () => _tokenStorage.getTokens();
|
|
@@ -84,7 +90,7 @@ function OAuthStrategy(config) {
|
|
|
84
90
|
const tokensResponse = await fetchTokens({
|
|
85
91
|
clientId: config.clientId,
|
|
86
92
|
grantType: 'anonymous',
|
|
87
|
-
});
|
|
93
|
+
}, _tokenRequestHeaders);
|
|
88
94
|
return {
|
|
89
95
|
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
90
96
|
refreshToken: {
|
|
@@ -97,7 +103,7 @@ function OAuthStrategy(config) {
|
|
|
97
103
|
const tokensResponse = await fetchTokens({
|
|
98
104
|
refreshToken: refreshToken.value,
|
|
99
105
|
grantType: 'refresh_token',
|
|
100
|
-
});
|
|
106
|
+
}, _tokenRequestHeaders);
|
|
101
107
|
const accessToken = (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in);
|
|
102
108
|
return {
|
|
103
109
|
accessToken,
|
|
@@ -178,7 +184,7 @@ function OAuthStrategy(config) {
|
|
|
178
184
|
...(oauthData.redirectUri && { redirectUri: oauthData.redirectUri }),
|
|
179
185
|
code,
|
|
180
186
|
codeVerifier: oauthData.codeVerifier,
|
|
181
|
-
});
|
|
187
|
+
}, _tokenRequestHeaders);
|
|
182
188
|
return {
|
|
183
189
|
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
184
190
|
refreshToken: {
|
|
@@ -353,6 +359,7 @@ function OAuthStrategy(config) {
|
|
|
353
359
|
member_id: memberId,
|
|
354
360
|
}, {
|
|
355
361
|
Authorization: getTokens().accessToken.value + ',' + apiKey,
|
|
362
|
+
..._tokenRequestHeaders,
|
|
356
363
|
});
|
|
357
364
|
return {
|
|
358
365
|
accessToken: (0, tokenHelpers_js_1.createAccessToken)(tokensResponse.access_token, tokensResponse.expires_in),
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { authentication } from '@wix/identity';
|
|
2
2
|
import { AuthenticationStrategy } from '@wix/sdk-types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for token-related API requests.
|
|
5
|
+
*/
|
|
6
|
+
export interface TokenRequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Custom headers to include in the token request.
|
|
9
|
+
* Useful for passing 'client-binding' header in public rendering flows.
|
|
10
|
+
*/
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
3
13
|
export interface Tokens {
|
|
4
14
|
accessToken: AccessToken;
|
|
5
15
|
refreshToken: RefreshToken;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/sdk",
|
|
3
|
-
"version": "1.21.
|
|
3
|
+
"version": "1.21.3",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Ronny Ringel",
|
|
6
6
|
"email": "ronnyr@wix.com"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"@wix/image-kit": "^1.114.0",
|
|
11
11
|
"@wix/redirects": "^1.0.70",
|
|
12
12
|
"@wix/sdk-context": "0.0.1",
|
|
13
|
-
"@wix/sdk-runtime": "1.0.
|
|
14
|
-
"@wix/sdk-types": "1.17.
|
|
13
|
+
"@wix/sdk-runtime": "1.0.7",
|
|
14
|
+
"@wix/sdk-types": "1.17.3",
|
|
15
15
|
"jose": "^5.10.0",
|
|
16
16
|
"type-fest": "^4.41.0"
|
|
17
17
|
},
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@wix/events": "^1.0.382",
|
|
24
24
|
"@wix/metro": "^1.0.93",
|
|
25
25
|
"@wix/metro-runtime": "^1.1891.0",
|
|
26
|
-
"@wix/sdk-runtime": "1.0.
|
|
26
|
+
"@wix/sdk-runtime": "1.0.7",
|
|
27
27
|
"eslint": "^8.57.1",
|
|
28
28
|
"eslint-config-sdk": "1.0.0",
|
|
29
29
|
"graphql": "^16.8.0",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"yoshiFlowLibrary": {
|
|
127
127
|
"buildEsmWithBabel": true
|
|
128
128
|
},
|
|
129
|
-
"falconPackageHash": "
|
|
129
|
+
"falconPackageHash": "85c30d8bf85fa6b345737b139ab7ebaf274735a08a7bcac2a23b5ebf"
|
|
130
130
|
}
|