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

companion: read state from session in oauth-redirect controller #2096

Merged
merged 2 commits into from
Feb 28, 2020
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
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