Browse Source

companion-client: support options cookies send rule (#2618)

* companion-client: support options cookies send rule

fixes #2241

* companion-client: prefix cookiesSendRule option with "companion"

* companion-client: set "companionCookiesRule" as optional field
Ifedapo .A. Olarewaju 4 years ago
parent
commit
3b5d19f363

+ 3 - 3
packages/@uppy/companion-client/src/RequestClient.js

@@ -135,7 +135,7 @@ module.exports = class RequestClient {
         fetchWithNetworkError(this._getUrl(path), {
           method: 'get',
           headers: headers,
-          credentials: 'same-origin'
+          credentials: this.opts.companionCookiesRule || 'same-origin'
         }))
       .then(this._getPostResponseFunc(skipPostResponse))
       .then((res) => this._json(res))
@@ -151,7 +151,7 @@ module.exports = class RequestClient {
         fetchWithNetworkError(this._getUrl(path), {
           method: 'post',
           headers: headers,
-          credentials: 'same-origin',
+          credentials: this.opts.companionCookiesRule || 'same-origin',
           body: JSON.stringify(data)
         }))
       .then(this._getPostResponseFunc(skipPostResponse))
@@ -168,7 +168,7 @@ module.exports = class RequestClient {
         fetchWithNetworkError(`${this.hostname}/${path}`, {
           method: 'delete',
           headers: headers,
-          credentials: 'same-origin',
+          credentials: this.opts.companionCookiesRule || 'same-origin',
           body: data ? JSON.stringify(data) : null
         }))
       .then(this._getPostResponseFunc(skipPostResponse))

+ 1 - 0
packages/@uppy/companion-client/types/index.d.ts

@@ -11,6 +11,7 @@ export interface TokenStorage {
 export interface RequestClientOptions {
   companionUrl: string
   companionHeaders?: object
+  companionCookiesRule?: RequestCredentials
   /**
    * Deprecated, use `companionHeaders` instead.
    */

+ 1 - 0
packages/@uppy/dropbox/src/index.js

@@ -23,6 +23,7 @@ module.exports = class Dropbox extends Plugin {
     this.provider = new Provider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'dropbox',
       pluginId: this.id
     })

+ 1 - 0
packages/@uppy/facebook/src/index.js

@@ -23,6 +23,7 @@ module.exports = class Facebook extends Plugin {
     this.provider = new Provider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'facebook',
       pluginId: this.id
     })

+ 1 - 0
packages/@uppy/google-drive/src/index.js

@@ -24,6 +24,7 @@ module.exports = class GoogleDrive extends Plugin {
     this.provider = new Provider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'drive',
       pluginId: this.id
     })

+ 1 - 0
packages/@uppy/instagram/src/index.js

@@ -23,6 +23,7 @@ module.exports = class Instagram extends Plugin {
     this.provider = new Provider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'instagram',
       pluginId: this.id
     })

+ 1 - 0
packages/@uppy/onedrive/src/index.js

@@ -26,6 +26,7 @@ module.exports = class OneDrive extends Plugin {
     this.provider = new Provider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'onedrive',
       pluginId: this.id
     })

+ 1 - 0
packages/@uppy/unsplash/src/index.js

@@ -34,6 +34,7 @@ module.exports = class Unsplash extends Plugin {
     this.provider = new SearchProvider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'unsplash',
       pluginId: this.id
     })

+ 1 - 0
packages/@uppy/zoom/src/index.js

@@ -24,6 +24,7 @@ module.exports = class Zoom extends Plugin {
     this.provider = new Provider(uppy, {
       companionUrl: this.opts.companionUrl,
       companionHeaders: this.opts.companionHeaders || this.opts.serverHeaders,
+      companionCookiesRule: this.opts.companionCookiesRule,
       provider: 'zoom',
       pluginId: this.id
     })

+ 4 - 0
website/src/docs/aws-s3-multipart.md

@@ -60,6 +60,10 @@ Custom headers that should be sent along to [Companion](/docs/companion) on ever
 
 This will be used by the default implementations of the upload-related functions below. If you provide your own implementations, these headers are not sent automatically.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `getChunkSize(file)`
 
 A function that returns the minimum chunk size to use when uploading the given file.

+ 4 - 0
website/src/docs/dropbox.md

@@ -119,6 +119,10 @@ This value can be a `String`, a `Regex` pattern, or an `Array` of both.
 
 This is useful when you have your [Companion](/docs/companion) running on multiple hosts. Otherwise, the default value should do just fine.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.

+ 4 - 0
website/src/docs/facebook.md

@@ -80,6 +80,10 @@ This value can be a `String`, a `Regex` pattern, or an `Array` of both.
 
 This is useful when you have your [Companion](/docs/companion) running on multiple hosts. Otherwise, the default value should be good enough.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.

+ 4 - 0
website/src/docs/google-drive.md

@@ -115,6 +115,10 @@ This value can be a `String`, a `Regex` pattern, or an `Array` of both.
 
 This is useful when you have your [Companion](/docs/companion) running on multiple hosts. Otherwise, the default value should be good enough.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.

+ 4 - 0
website/src/docs/instagram.md

@@ -86,6 +86,10 @@ This value can be a `String`, a `Regex` pattern, or an `Array` of both.
 
 This is useful when you have your [Companion](/docs/companion) running on multiple hosts. Otherwise, the default value should be good enough.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.

+ 4 - 0
website/src/docs/onedrive.md

@@ -80,6 +80,10 @@ This value can be a `String`, a `Regex` pattern, or an `Array` of both.
 
 This is useful when you have your [Companion](/docs/companion) running on multiple hosts. Otherwise, the default value should be good enough.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.

+ 4 - 0
website/src/docs/url.md

@@ -78,6 +78,10 @@ DOM element, CSS selector, or plugin to mount the URL provider into. This should
 
 URL to an Companion instance.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.

+ 4 - 0
website/src/docs/zoom.md

@@ -84,6 +84,10 @@ This value can be a `String`, a `Regex` pattern, or an `Array` of both.
 
 This is useful when you have your [Companion](/docs/companion) running on multiple hosts. Otherwise, the default value should be good enough.
 
+### `companionCookiesRule: 'same-origin'`
+
+This option correlates to the [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials), which tells the plugin whether or not to send cookies to [Companion](/docs/companion).
+
 ### `locale: {}`
 
 Localize text that is shown to the user.