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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading