Skip to content

Commit

Permalink
@uppy/companion: fix code for custom providers (#5398)
Browse files Browse the repository at this point in the history
Fixes: #5383
  • Loading branch information
mifi authored Aug 15, 2024
1 parent 27e24ce commit b332e83
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/companion.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/controllers/preauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function preauth (req, res) {
}

const providerConfig = req.companion.options.providerOptions[req.params.providerName]
if (!providerConfig.credentialsURL) {
if (!providerConfig?.credentialsURL) {
return res.sendStatus(501)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const logger = require('../logger')
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
Expand Down
5 changes: 3 additions & 2 deletions packages/@uppy/companion/src/server/middlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ 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()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports.getProviderMiddleware = (providers, grantConfig) => {
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 {
Expand Down

0 comments on commit b332e83

Please sign in to comment.