From c1407070fbb30eb4fb04cb6cb9f64be28f87fab7 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Tue, 22 Mar 2022 13:06:59 +0800 Subject: [PATCH] Small companion code and doc changes (#3586) * move migration guide for companion * improve doc * add comment about session usage * remove unused options.multipleInstances --- packages/@uppy/companion/src/companion.js | 2 +- .../@uppy/companion/src/standalone/helper.js | 1 - .../@uppy/companion/src/standalone/index.js | 4 ++ website/src/docs/companion.md | 37 +------------------ website/src/docs/migration-guides.md | 35 ++++++++++++++++++ 5 files changed, 41 insertions(+), 38 deletions(-) diff --git a/packages/@uppy/companion/src/companion.js b/packages/@uppy/companion/src/companion.js index 7b403de72..bdd2a5274 100644 --- a/packages/@uppy/companion/src/companion.js +++ b/packages/@uppy/companion/src/companion.js @@ -79,7 +79,7 @@ module.exports.app = (optionsArg = {}) => { if (options.redisUrl) { redis.client(merge({ url: options.redisUrl }, options.redisOptions || {})) } - emitter(options.multipleInstances && options.redisUrl, options.redisPubSubScope) + emitter(options.redisUrl, options.redisPubSubScope) const app = express() diff --git a/packages/@uppy/companion/src/standalone/helper.js b/packages/@uppy/companion/src/standalone/helper.js index 7d87d14c3..af3e2d489 100644 --- a/packages/@uppy/companion/src/standalone/helper.js +++ b/packages/@uppy/companion/src/standalone/helper.js @@ -109,7 +109,6 @@ const getConfigFromEnv = () => { allowLocalUrls: process.env.COMPANION_ALLOW_LOCAL_URLS === 'true', // cookieDomain is kind of a hack to support distributed systems. This should be improved but we never got so far. cookieDomain: process.env.COMPANION_COOKIE_DOMAIN, - multipleInstances: true, streamingUpload: process.env.COMPANION_STREAMING_UPLOAD === 'true', maxFileSize: process.env.COMPANION_MAX_FILE_SIZE ? parseInt(process.env.COMPANION_MAX_FILE_SIZE, 10) : undefined, chunkSize: process.env.COMPANION_CHUNK_SIZE ? parseInt(process.env.COMPANION_CHUNK_SIZE, 10) : undefined, diff --git a/packages/@uppy/companion/src/standalone/index.js b/packages/@uppy/companion/src/standalone/index.js index 0f546ff3a..bb9c493e4 100644 --- a/packages/@uppy/companion/src/standalone/index.js +++ b/packages/@uppy/companion/src/standalone/index.js @@ -153,6 +153,10 @@ module.exports = function server (inputCompanionOptions = {}) { } } + // Session is used for grant redirects, so that we don't need to expose secret tokens in URLs + // See https://github.com/transloadit/uppy/pull/1668 + // https://github.com/transloadit/uppy/issues/3538#issuecomment-1069232909 + // https://github.com/simov/grant#callback-session router.use(session(sessionOptions)) // Routes diff --git a/website/src/docs/companion.md b/website/src/docs/companion.md index 763d24739..a8a4ea901 100644 --- a/website/src/docs/companion.md +++ b/website/src/docs/companion.md @@ -337,7 +337,7 @@ const options = { * `protocol` - `http | https` - even though companion itself always runs as http, you may want to set this to `https` if you are running a reverse https proxy in front of companion. * `host` (required) - your server’s publically facing hostname (for example `example.com`). -* `oauthDomain` - if you have several instances of Companion with different (and perhaps dynamic) subdomains, you can set a single fixed domain (e.g `sub1.example.com`) to handle your OAuth authentication for you. This would then redirect back to the correct instance with the required credentials on completion. This way you only need to configure a single callback URL for OAuth providers. +* `oauthDomain` - if you have several instances of Companion with different (and perhaps dynamic) subdomains, you can set a single fixed subdomain and server (e.g `sub1.example.com`) to handle your OAuth authentication for you. This would then redirect back to the correct instance with the required credentials on completion. This way you only need to configure a single callback URL for OAuth providers. * `path` - the server path to where the Uppy app is sitting (e.g if Companion is at `example.com/companion`, then the path would be `/companion`). * `implicitPath` - if the URL’s path in your reverse proxy is different from your Companion path in your express app, then you need to set this path as `implicitPath`. So if your Companion URL is `example.com/mypath/companion`. Where the path `/mypath` is defined in your NGINX server, while `/companion` is set in your express app. Then you need to set the option `implicitPath` to `/mypath`, and set the `path` option to `/companion`. * `validHosts` - if you are setting an `oauthDomain`, you need to set a list of valid hosts, so the oauth handler can validate the host of the Uppy instance requesting the authentication. This is essentially a list of valid domains running your Companion instances. The list may also contain regex patterns. e.g `['sub2.example.com', 'sub3.example.com', '(\\w+).example.com']` @@ -541,41 +541,6 @@ See also [example code with a custom provider](https://github.com/transloadit/up } ``` -## Migrating v1 to v2 - -### Prerequisite - -Since v2, you now need to be running `node.js >= v10.20.1` to use Companion. - -### ProviderOptions - -In v2 the `google` and `microsoft` [providerOptions](https://uppy.io/docs/companion/#Options) have been changed to `drive` and `onedrive` respectively. - -### OAuth Redirect URIs - -On your Providers’ respective developer platforms, the OAuth redirect URIs that you should supply has now changed from: - -`http(s)://$COMPANION_HOST_NAME/connect/$AUTH_PROVIDER/callback` in v1 - -to: - -`http(s)://$COMPANION_HOST_NAME/$PROVIDER_NAME/redirect` in v2 - -#### New Redirect URIs - -
- -| Provider | New Redirect URI -|-|-| -| Dropbox | `https://$COMPANION_HOST_NAME/dropbox/redirect` | -| Google Drive | `https://$COMPANION_HOST_NAME/drive/redirect` | -| OneDrive | `https://$COMPANION_HOST_NAME/onedrive/redirect` | -| Box | `https://$YOUR_COMPANION_HOST_NAME/box/redirect` | -| Facebook | `https://$COMPANION_HOST_NAME/facebook/redirect` | -| Instagram | `https://$COMPANION_HOST_NAME/instagram/redirect` | - -
- ## Development 1\. To set up Companion for local development, please clone the Uppy repo and install, like so: diff --git a/website/src/docs/migration-guides.md b/website/src/docs/migration-guides.md index 195ea6058..ac81b6b77 100644 --- a/website/src/docs/migration-guides.md +++ b/website/src/docs/migration-guides.md @@ -247,6 +247,41 @@ Uppy 1.0 will continue to receive bug fixes for three more months (until