Skip to content

Commit

Permalink
Merge pull request #2096 from transloadit/oauth-redirect-state
Browse files Browse the repository at this point in the history
companion: read state from session in oauth-redirect controller
  • Loading branch information
ifedapoolarewaju authored Feb 28, 2020
2 parents a09d76b + b59d5b4 commit 4d00ef3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ const oAuthState = require('../helpers/oauth-state')
* @param {object} res
*/
module.exports = function oauthRedirect (req, res) {
if (!req.query.state) {
return res.status(400).send('Cannot find state param in reques')
const dynamic = (req.session.grant || {}).dynamic || {}
const state = dynamic.state
if (!state) {
return res.status(400).send('Cannot find state in session')
}
const handler = oAuthState.getFromState(req.query.state, 'companionInstance', req.companion.options.secret)
const handler = oAuthState.getFromState(state, 'companionInstance', req.companion.options.secret)
const handlerHostName = parseUrl(handler).host

if (hasMatch(handlerHostName, req.companion.options.server.validHosts)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@uppy/companion/test/mockserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { app } = require('../src/standalone')

const express = require('express')
const session = require('express-session')
var authServer = express()
const authServer = express()

authServer.use(session({ secret: 'grant', resave: true, saveUninitialized: true }))
authServer.all('*/callback', (req, res, next) => {
Expand All @@ -11,7 +11,7 @@ authServer.all('*/callback', (req, res, next) => {
}
next()
})
authServer.all('*/send-token', (req, res, next) => {
authServer.all(['*/send-token', '*/redirect'], (req, res, next) => {
req.session.grant = { dynamic: { state: req.query.state || 'non-empty-value' } }
next()
})
Expand Down

0 comments on commit 4d00ef3

Please sign in to comment.