浏览代码

companion: change oauth access token transport method

Ifedapo Olarewaju 6 年之前
父节点
当前提交
4942067513

+ 1 - 0
CHANGELOG.md

@@ -109,6 +109,7 @@ PRs are welcome! Please do open an issue to discuss first if it's a big feature,
 - [x] companion: remove deprecated "authorized" endpoint
 - [x] companion: remove default upload protocol
 - [x] companion: remove fallback `UPPYSERVER_*` env options
+- [x] companion: change OAuth access token transport
 
 ## 1.0 Goals
 

+ 3 - 0
packages/@uppy/companion/src/config/grant.js

@@ -2,17 +2,20 @@
 module.exports = () => {
   return {
     google: {
+      transport: 'session',
       scope: [
         'https://www.googleapis.com/auth/drive.readonly'
       ],
       callback: '/drive/callback'
     },
     dropbox: {
+      transport: 'session',
       authorize_url: 'https://www.dropbox.com/oauth2/authorize',
       access_url: 'https://api.dropbox.com/oauth2/token',
       callback: '/dropbox/callback'
     },
     instagram: {
+      transport: 'session',
       callback: '/instagram/callback'
     }
   }

+ 1 - 2
packages/@uppy/companion/src/server/controllers/callback.js

@@ -17,8 +17,7 @@ module.exports = function callback (req, res, next) {
     req.uppy.providerTokens = {}
   }
 
-  // TODO see if the access_token can be transported in a different way that url query params
-  req.uppy.providerTokens[providerName] = req.query.access_token
+  req.uppy.providerTokens[providerName] = req.session.grant.response.access_token
   logger.debug(`Generating auth token for provider ${providerName}.`)
   const uppyAuthToken = tokenService.generateToken(req.uppy.providerTokens, req.uppy.options.secret)
   return res.redirect(req.uppy.buildURL(`/${providerName}/send-token?uppyAuthToken=${uppyAuthToken}`, true))

+ 0 - 1
packages/@uppy/companion/src/standalone/helper.js

@@ -28,7 +28,6 @@ const getConfigFromEnv = () => {
   const validHosts = domains ? domains.split(',') : []
 
   return {
-    // TODO: Rename providerOptions to providers.
     providerOptions: {
       google: {
         key: process.env.COMPANION_GOOGLE_KEY,

+ 6 - 0
packages/@uppy/companion/test/mockserver.js

@@ -5,6 +5,12 @@ const session = require('express-session')
 var authServer = express()
 
 authServer.use(session({ secret: 'grant', resave: true, saveUninitialized: true }))
+authServer.all('*/callback', (req, res, next) => {
+  req.session.grant = {
+    response: {access_token: 'fake token'}
+  }
+  next()
+})
 authServer.all('/drive/send-token', (req, res, next) => {
   req.session.grant = {
     state: 'non-empty-value' }