Skip to content

Commit 67d8595

Browse files
committed
fix bug with dynamic grant config
1 parent 96eb565 commit 67d8595

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

packages/@uppy/companion/src/companion.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ module.exports.app = (optionsArg = {}) => {
142142
if (options.testDynamicOauthCredentials) {
143143
app.post('/:providerName/test-dynamic-oauth-credentials', (req, res) => {
144144
if (req.query.secret !== options.testDynamicOauthCredentialsSecret) throw new Error('Invalid secret')
145-
logger.info('Returning dynamic OAuth2 credentials')
146145
const { providerName } = req.params
146+
logger.info(`Returning dynamic OAuth2 credentials for ${providerName}`)
147147
// for simplicity, we just return the normal credentials for the provider, but in a real-world scenario,
148148
// we would query based on parameters
149149
const { key, secret } = options.providerOptions[providerName]

packages/@uppy/companion/src/server/controllers/connect.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const queryString = (params, prefix = '?') => {
1212
* @param {object} req
1313
* @param {object} res
1414
*/
15-
module.exports = function connect (req, res) {
15+
module.exports = function connect(req, res) {
1616
const { secret } = req.companion.options
1717
const stateObj = oAuthState.generateState()
1818

@@ -37,7 +37,17 @@ module.exports = function connect (req, res) {
3737
const { provider, providerGrantConfig } = req.companion
3838

3939
// pass along grant's dynamic config (if specified for the provider in its grant config `dynamic` section)
40-
const grantDynamicConfig = Object.fromEntries(providerGrantConfig.dynamic?.map(p => [p, req.query[p]]) || [])
40+
// this is needed for things like custom oauth domain (e.g. webdav)
41+
const grantDynamicConfig = Object.fromEntries(providerGrantConfig.dynamic?.flatMap((dynamicKey) => {
42+
const queryValue = req.query[dynamicKey];
43+
44+
// note: when using credentialsURL (dynamic oauth credentials), dynamic has ['key', 'secret', 'redirect_uri']
45+
// but in that case, query string is empty, so we need to only fetch these parameters from QS if they exist.
46+
if (!queryValue) return []
47+
return [[
48+
dynamicKey, queryValue
49+
]]
50+
}) || [])
4151

4252
const providerName = provider.authProvider
4353
const qs = queryString({

packages/@uppy/companion/src/server/provider/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const providerNameToAuthName = (name, options) => { // eslint-disable-line no-un
3636
return (providers[name] || {}).authProvider
3737
}
3838

39-
function getGrantConfigForProvider ({ providerName, companionOptions, grantConfig }) {
39+
function getGrantConfigForProvider({ providerName, companionOptions, grantConfig }) {
4040
const authProvider = providerNameToAuthName(providerName, companionOptions)
4141

4242
if (!isOAuthProvider(authProvider)) return undefined

0 commit comments

Comments
 (0)