From 3d89a0cb4b9ab4b32430e784a4d7a273ea0db2d3 Mon Sep 17 00:00:00 2001 From: Ifedapo Olarewaju Date: Sun, 10 Feb 2019 12:26:02 +0100 Subject: [PATCH] companion: use redirect strategy if redirect value is set in auth url --- .../src/server/controllers/callback.js | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/packages/@uppy/companion/src/server/controllers/callback.js b/packages/@uppy/companion/src/server/controllers/callback.js index a8ebae51d..29bfab6b2 100644 --- a/packages/@uppy/companion/src/server/controllers/callback.js +++ b/packages/@uppy/companion/src/server/controllers/callback.js @@ -34,20 +34,34 @@ module.exports = function callback (req, res, next) { const allowedClients = req.uppy.options.clients // if no preset clients then allow any client if (!allowedClients || hasMatch(origin, allowedClients) || hasMatch(parseUrl(origin).host, allowedClients)) { - return res.send(` - - - - - - - - ` - ) + const redirect = oAuthState.getFromState(state, 'redirect', req.uppy.options.secret) + if (redirect) { + // if a redirect value is specified from the client, then redirect there instead + const query = (parseUrl(redirect).query ? `&` : `?`) + `uppyAuthToken=${uppyAuthToken}` + return res.redirect(`${redirect}${query}`) + } + return res.send(htmlContent(uppyAuthToken, origin)) } } next() } + +/** + * + * @param {string} token uppy auth token + * @param {string} origin url string + */ +const htmlContent = (token, origin) => { + return ` + + + + + + + + ` +}