Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix code for custom providers #5398

Merged
merged 2 commits into from
Aug 15, 2024
Merged

fix code for custom providers #5398

merged 2 commits into from
Aug 15, 2024

Conversation

mifi
Copy link
Contributor

@mifi mifi commented Aug 9, 2024

closes #5383

Copy link
Contributor

github-actions bot commented Aug 9, 2024

Diff output files
diff --git a/packages/@uppy/companion/lib/companion.js b/packages/@uppy/companion/lib/companion.js
index 94f7d77..9416e5e 100644
--- a/packages/@uppy/companion/lib/companion.js
+++ b/packages/@uppy/companion/lib/companion.js
@@ -207,7 +207,7 @@ module.exports.app = (optionsArg = {}) => {
       logger.info(`Returning dynamic OAuth2 credentials for ${providerName}`);
       // for simplicity, we just return the normal credentials for the provider, but in a real-world scenario,
       // we would query based on parameters
-      const { key, secret } = options.providerOptions[providerName];
+      const { key, secret } = options.providerOptions[providerName] ?? { __proto__: null };
       function getRedirectUri() {
         const oauthProvider = getOauthProvider(providerName);
         if (!isOAuthProvider(oauthProvider)) {
diff --git a/packages/@uppy/companion/lib/server/controllers/preauth.js b/packages/@uppy/companion/lib/server/controllers/preauth.js
index b912f45..e957ba2 100644
--- a/packages/@uppy/companion/lib/server/controllers/preauth.js
+++ b/packages/@uppy/companion/lib/server/controllers/preauth.js
@@ -8,7 +8,7 @@ function preauth(req, res) {
     return res.sendStatus(400);
   }
   const providerConfig = req.companion.options.providerOptions[req.params.providerName];
-  if (!providerConfig.credentialsURL) {
+  if (!providerConfig?.credentialsURL) {
     return res.sendStatus(501);
   }
   const preAuthToken = tokenService.generateEncryptedToken(req.body.params, req.companion.options.preAuthSecret);
diff --git a/packages/@uppy/companion/lib/server/controllers/refresh-token.js b/packages/@uppy/companion/lib/server/controllers/refresh-token.js
index 34f4fdc..7d05180 100644
--- a/packages/@uppy/companion/lib/server/controllers/refresh-token.js
+++ b/packages/@uppy/companion/lib/server/controllers/refresh-token.js
@@ -8,7 +8,8 @@ const logger = require("../logger");
 // https://github.com/simov/grant/issues/149
 async function refreshToken(req, res, next) {
   const { providerName } = req.params;
-  const { key: clientId, secret: clientSecret } = req.companion.options.providerOptions[providerName];
+  const { key: clientId, secret: clientSecret } = req.companion.options.providerOptions[providerName]
+    ?? { __proto__: null };
   const { redirect_uri: redirectUri } = req.companion.providerGrantConfig;
   const { providerUserSession } = req.companion;
   // not all providers have refresh tokens
diff --git a/packages/@uppy/companion/lib/server/middlewares.js b/packages/@uppy/companion/lib/server/middlewares.js
index 1648c3c..795bb5d 100644
--- a/packages/@uppy/companion/lib/server/middlewares.js
+++ b/packages/@uppy/companion/lib/server/middlewares.js
@@ -79,13 +79,14 @@ exports.verifyToken = (req, res, next) => {
   if (!isOAuthProviderReq(req)) {
     const { providerOptions } = req.companion.options;
     const { providerName } = req.params;
-    if (!providerOptions[providerName] || !providerOptions[providerName].key) {
+    const key = providerOptions[providerName]?.key;
+    if (!key) {
       logger.info(`unconfigured credentials for ${providerName}`, "non.oauth.token.load.unset", req.id);
       res.sendStatus(501);
       return;
     }
     req.companion.providerUserSession = {
-      accessToken: providerOptions[providerName].key,
+      accessToken: key,
     };
     next();
   }
diff --git a/packages/@uppy/companion/lib/server/provider/index.js b/packages/@uppy/companion/lib/server/provider/index.js
index 833dffa..7691d83 100644
--- a/packages/@uppy/companion/lib/server/provider/index.js
+++ b/packages/@uppy/companion/lib/server/provider/index.js
@@ -47,7 +47,7 @@ module.exports.getProviderMiddleware = (providers, grantConfig) => {
         providerGrantConfig = grantConfig[oauthProvider];
         req.companion.providerGrantConfig = providerGrantConfig;
       }
-      const { secret } = providerOptions[providerName];
+      const secret = providerOptions[providerName]?.secret;
       req.companion.provider = new ProviderClass({ secret, providerName, providerGrantConfig, allowLocalUrls });
       req.companion.providerClass = ProviderClass;
     } else {

@aduh95 aduh95 merged commit b332e83 into main Aug 15, 2024
20 checks passed
@aduh95 aduh95 deleted the fix-custom-providers branch August 15, 2024 17:14
@github-actions github-actions bot mentioned this pull request Aug 15, 2024
github-actions bot added a commit that referenced this pull request Aug 16, 2024
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3           |   4.0.3 | @uppy/provider-views   |   4.0.1 |
| @uppy/companion        |   5.0.5 | @uppy/status-bar       |   4.0.2 |
| @uppy/companion-client |   4.0.1 | @uppy/transloadit      |   4.0.2 |
| @uppy/core             |   4.1.1 | @uppy/tus              |   4.0.1 |
| @uppy/dashboard        |   4.0.3 | @uppy/utils            |   6.0.2 |
| @uppy/drag-drop        |   4.0.2 | @uppy/vue              |   2.0.1 |
| @uppy/file-input       |   4.0.1 | uppy                   |   4.1.1 |
| @uppy/image-editor     |   3.0.1 |                        |         |

- @uppy/transloadit: fix issue with `allowMultipleUploadBatches` (Mikael Finstad / #5400)
- meta: Bump elliptic from 6.5.5 to 6.5.7 (dependabot[bot] / #5410)
- meta: add back patch for `p-queue` (Antoine du Hamel / #5409)
- @uppy/transloadit: fix many lurking `TypeError` (Mikael Finstad / #5399)
- docs: improve `corsOrigins` documentation (Mikael Finstad / #5390)
- docs: add `ViewEncapsulation` to Angular example (Aaron Russell / #5395)
- @uppy/companion: fix code for custom providers (Mikael Finstad / #5398)
- docs: add note about throwing in `cancelAll` and `destroy()` (Mikael Finstad / #5408)
- meta: Bump docker/login-action from 3.2.0 to 3.3.0 (dependabot[bot] / #5372)
- meta: Bump docker/setup-qemu-action from 3.1.0 to 3.2.0 (dependabot[bot] / #5370)
- docs: make hosted Companion more clear (Merlijn Vos / #5394)
- meta: Bump docker/build-push-action from 6.4.1 to 6.6.1 (dependabot[bot] / #5403)
- meta: bump p-queue to latest, remove patch (Mikael Finstad / #5391)
- meta: enforce `.ts` extension for relative import types (Antoine du Hamel / #5393)
- @uppy/tus: Fix onShouldRetry type signature (Trent Nadeau / #5387)
- @uppy/dashboard,@uppy/drag-drop,@uppy/file-input: Transform the `accept` prop into a string everywhere (Evgenia Karunus / #5380)
- docs: fix getTemporarySecurityCredentials in aws-s3 (Merlijn Vos / #5363)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Recent commit caused custom providers to break
2 participants