-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 tasks
Diff output filesdiff --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
reviewed
Aug 15, 2024
aduh95
reviewed
Aug 15, 2024
packages/@uppy/companion/src/server/controllers/refresh-token.js
Outdated
Show resolved
Hide resolved
aduh95
approved these changes
Aug 15, 2024
Merged
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #5383