|
@@ -1,8 +1,26 @@
|
|
|
/**
|
|
|
* oAuth callback. Encrypts the access token and sends the new token with the response,
|
|
|
*/
|
|
|
+const serialize = require('serialize-javascript')
|
|
|
+
|
|
|
const tokenService = require('../helpers/jwt')
|
|
|
const logger = require('../logger')
|
|
|
+const oAuthState = require('../helpers/oauth-state')
|
|
|
+
|
|
|
+const closePageHtml = (origin) => `
|
|
|
+ <!DOCTYPE html>
|
|
|
+ <html>
|
|
|
+ <head>
|
|
|
+ <meta charset="utf-8" />
|
|
|
+ <script>
|
|
|
+ // if window.opener is nullish, we want the following line to throw to avoid
|
|
|
+ // the window closing without informing the user.
|
|
|
+ window.opener.postMessage(${serialize({ error: true })}, ${serialize(origin)})
|
|
|
+ window.close()
|
|
|
+ </script>
|
|
|
+ </head>
|
|
|
+ <body>Authentication failed.</body>
|
|
|
+ </html>`
|
|
|
|
|
|
/**
|
|
|
*
|
|
@@ -27,5 +45,7 @@ module.exports = function callback (req, res, next) { // eslint-disable-line no-
|
|
|
|
|
|
logger.debug(`Did not receive access token for provider ${providerName}`, null, req.id)
|
|
|
logger.debug(grant.response, 'callback.oauth.resp', req.id)
|
|
|
- return res.sendStatus(400)
|
|
|
+ const state = oAuthState.getDynamicStateFromRequest(req)
|
|
|
+ const origin = state && oAuthState.getFromState(state, 'origin', req.companion.options.secret)
|
|
|
+ return res.status(400).send(closePageHtml(origin))
|
|
|
}
|