@bytescale/sdk 3.15.0 → 3.17.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/dist/browser/cjs/main.js
CHANGED
|
@@ -2597,7 +2597,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2597
2597
|
_session$params = session.params;
|
|
2598
2598
|
return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
|
|
2599
2599
|
return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
|
|
2600
|
-
|
|
2600
|
+
// We don't use cookie-based auth if the browser supports service worker-based auth, as using both will cause
|
|
2601
|
+
// confusion for us in the future (i.e. we may question "do we need to use both together? was there a reason?").
|
|
2602
|
+
// Also: if the user has omitted "allowedOrigins" from their JWT, then service worker-based auth is more secure
|
|
2603
|
+
// than cookie-based auth, which is another reason to prevent these cookies from being set unless required.
|
|
2604
|
+
var setCookie = !_this6.isUsingServiceWorker(session);
|
|
2605
|
+
return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt, setCookie), function (setTokenResult) {
|
|
2601
2606
|
_this6.setServiceWorkerConfig(session, [{
|
|
2602
2607
|
headers: [{
|
|
2603
2608
|
key: "Authorization",
|
|
@@ -2636,6 +2641,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2636
2641
|
return Promise.reject(e);
|
|
2637
2642
|
}
|
|
2638
2643
|
}
|
|
2644
|
+
}, {
|
|
2645
|
+
key: "isUsingServiceWorker",
|
|
2646
|
+
value: function isUsingServiceWorker(session) {
|
|
2647
|
+
return session.authServiceWorker !== undefined;
|
|
2648
|
+
}
|
|
2639
2649
|
}, {
|
|
2640
2650
|
key: "setServiceWorkerConfig",
|
|
2641
2651
|
value: function setServiceWorkerConfig(session, config) {
|
|
@@ -2648,8 +2658,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2648
2658
|
}
|
|
2649
2659
|
}, {
|
|
2650
2660
|
key: "getAccessTokenUrl",
|
|
2651
|
-
value: function getAccessTokenUrl(params) {
|
|
2652
|
-
return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId);
|
|
2661
|
+
value: function getAccessTokenUrl(params, setCookie) {
|
|
2662
|
+
return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId, "?set-cookie=").concat(setCookie ? "true" : "false");
|
|
2653
2663
|
}
|
|
2654
2664
|
}, {
|
|
2655
2665
|
key: "getCdnUrl",
|
|
@@ -2663,7 +2673,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2663
2673
|
try {
|
|
2664
2674
|
var _this8 = this;
|
|
2665
2675
|
var _a;
|
|
2666
|
-
return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
|
|
2676
|
+
return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params, true), {
|
|
2667
2677
|
method: "DELETE",
|
|
2668
2678
|
credentials: "include",
|
|
2669
2679
|
headers: {}
|
|
@@ -2677,14 +2687,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2677
2687
|
}
|
|
2678
2688
|
}, {
|
|
2679
2689
|
key: "setAccessToken",
|
|
2680
|
-
value: function setAccessToken(params, jwt) {
|
|
2690
|
+
value: function setAccessToken(params, jwt, setCookie) {
|
|
2681
2691
|
try {
|
|
2682
2692
|
var _this10 = this;
|
|
2683
2693
|
var _a;
|
|
2684
2694
|
var request = {
|
|
2685
2695
|
accessToken: jwt
|
|
2686
2696
|
};
|
|
2687
|
-
return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
|
|
2697
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params, setCookie), {
|
|
2688
2698
|
method: "PUT",
|
|
2689
2699
|
credentials: "include",
|
|
2690
2700
|
headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
|
|
@@ -2582,7 +2582,12 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2582
2582
|
_session$params = session.params;
|
|
2583
2583
|
return AuthManagerBrowser_await(session.params.authHeaders(), function (_session$params$authH) {
|
|
2584
2584
|
return AuthManagerBrowser_await(_getAccessToken.call(_this6, _session$params, _session$params$authH), function (jwt) {
|
|
2585
|
-
|
|
2585
|
+
// We don't use cookie-based auth if the browser supports service worker-based auth, as using both will cause
|
|
2586
|
+
// confusion for us in the future (i.e. we may question "do we need to use both together? was there a reason?").
|
|
2587
|
+
// Also: if the user has omitted "allowedOrigins" from their JWT, then service worker-based auth is more secure
|
|
2588
|
+
// than cookie-based auth, which is another reason to prevent these cookies from being set unless required.
|
|
2589
|
+
var setCookie = !_this6.isUsingServiceWorker(session);
|
|
2590
|
+
return AuthManagerBrowser_await(_this6.setAccessToken(session.params, jwt, setCookie), function (setTokenResult) {
|
|
2586
2591
|
_this6.setServiceWorkerConfig(session, [{
|
|
2587
2592
|
headers: [{
|
|
2588
2593
|
key: "Authorization",
|
|
@@ -2621,6 +2626,11 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2621
2626
|
return Promise.reject(e);
|
|
2622
2627
|
}
|
|
2623
2628
|
}
|
|
2629
|
+
}, {
|
|
2630
|
+
key: "isUsingServiceWorker",
|
|
2631
|
+
value: function isUsingServiceWorker(session) {
|
|
2632
|
+
return session.authServiceWorker !== undefined;
|
|
2633
|
+
}
|
|
2624
2634
|
}, {
|
|
2625
2635
|
key: "setServiceWorkerConfig",
|
|
2626
2636
|
value: function setServiceWorkerConfig(session, config) {
|
|
@@ -2633,8 +2643,8 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2633
2643
|
}
|
|
2634
2644
|
}, {
|
|
2635
2645
|
key: "getAccessTokenUrl",
|
|
2636
|
-
value: function getAccessTokenUrl(params) {
|
|
2637
|
-
return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId);
|
|
2646
|
+
value: function getAccessTokenUrl(params, setCookie) {
|
|
2647
|
+
return "".concat(this.getCdnUrl(params), "/api/v1/access_tokens/").concat(params.accountId, "?set-cookie=").concat(setCookie ? "true" : "false");
|
|
2638
2648
|
}
|
|
2639
2649
|
}, {
|
|
2640
2650
|
key: "getCdnUrl",
|
|
@@ -2648,7 +2658,7 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2648
2658
|
try {
|
|
2649
2659
|
var _this8 = this;
|
|
2650
2660
|
var _a;
|
|
2651
|
-
return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params), {
|
|
2661
|
+
return AuthManagerBrowser_awaitIgnored(BaseAPI.fetch(_this8.getAccessTokenUrl(params, true), {
|
|
2652
2662
|
method: "DELETE",
|
|
2653
2663
|
credentials: "include",
|
|
2654
2664
|
headers: {}
|
|
@@ -2662,14 +2672,14 @@ var AuthManagerImpl = /*#__PURE__*/function () {
|
|
|
2662
2672
|
}
|
|
2663
2673
|
}, {
|
|
2664
2674
|
key: "setAccessToken",
|
|
2665
|
-
value: function setAccessToken(params, jwt) {
|
|
2675
|
+
value: function setAccessToken(params, jwt, setCookie) {
|
|
2666
2676
|
try {
|
|
2667
2677
|
var _this10 = this;
|
|
2668
2678
|
var _a;
|
|
2669
2679
|
var request = {
|
|
2670
2680
|
accessToken: jwt
|
|
2671
2681
|
};
|
|
2672
|
-
return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params), {
|
|
2682
|
+
return AuthManagerBrowser_await(BaseAPI.fetch(_this10.getAccessTokenUrl(params, setCookie), {
|
|
2673
2683
|
method: "PUT",
|
|
2674
2684
|
credentials: "include",
|
|
2675
2685
|
headers: AuthManagerBrowser_defineProperty({}, _this10.contentType, _this10.contentTypeJson),
|
|
@@ -19,9 +19,11 @@ export interface BeginAuthSessionParams {
|
|
|
19
19
|
*/
|
|
20
20
|
options?: Pick<BytescaleApiClientConfig, "fetchApi" | "cdnUrl">;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Enables support for modern browsers that block third-party cookies (like Safari).
|
|
23
23
|
*
|
|
24
|
-
*
|
|
24
|
+
* The value of this field must be the path to the service worker JavaScript file hosted at the root of your website.
|
|
25
|
+
*
|
|
26
|
+
* OVERVIEW:
|
|
25
27
|
*
|
|
26
28
|
* This feature works by running a "service worker" in the background that adds "Authorization" and "Authorization-Token"
|
|
27
29
|
* request headers to HTTP requests made to the Bytescale CDN. This allows the Bytescale CDN to authorize requests
|
|
@@ -30,21 +32,23 @@ export interface BeginAuthSessionParams {
|
|
|
30
32
|
* to block these cookies, meaning "Authorization" request headers must be used instead. Authorization headers can
|
|
31
33
|
* only be added to requests originating from page elements like "<img>" elements through the use of service workers.
|
|
32
34
|
*
|
|
33
|
-
*
|
|
35
|
+
* INSTRUCTIONS:
|
|
36
|
+
*
|
|
37
|
+
* 1. Your JWT must include the 'accountId' field at the root of the 'payload' section of the JWT (i.e. next to the 'exp' field).
|
|
34
38
|
*
|
|
35
|
-
*
|
|
39
|
+
* 2. Create a JavaScript file that contains the following line:
|
|
36
40
|
*
|
|
37
41
|
* importScripts("https://js.bytescale.com/auth-sw/v1");
|
|
38
42
|
*
|
|
39
|
-
*
|
|
43
|
+
* 3. Host this JavaScript file from your website:
|
|
40
44
|
*
|
|
41
|
-
*
|
|
45
|
+
* 3a. It MUST be under the ROOT directory of your website.
|
|
42
46
|
* (e.g. "/bytescale-auth-sw.js")
|
|
43
47
|
*
|
|
44
|
-
*
|
|
48
|
+
* 3b. It MUST be on the SAME DOMAIN as your website.
|
|
45
49
|
* (e.g. "www.example.com" and not "assets.example.com")
|
|
46
50
|
*
|
|
47
|
-
*
|
|
51
|
+
* 4. Specify the absolute path to your JavaScript file in the 'beginAuthSession' call.
|
|
48
52
|
* (e.g. { ..., serviceWorkerScript: "/bytescale-auth-sw.js" })
|
|
49
53
|
*
|
|
50
54
|
* Examples:
|