Last active
July 27, 2019 18:27
-
-
Save tobinbc/63e72eff397a15f6904103d72d7f9abe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import URLParse from 'url-parse' | |
chrome.webRequest.onHeadersReceived.addListener ( | |
details => { | |
let slackResponse = details.responseHeaders.find (header => header.name === 'x-slack-response') | |
let slackSJON = slackResponse ? slackResponse.value : JSON.stringify ({ok: false}) | |
let url = URLParse(details.url) | |
chrome.tabs.update (details.tabId, { | |
url: chrome.extension.getURL ( | |
`redirect.html?state=${encodeURIComponent (url.query.state || '')}&slack=${encodeURIComponent (slackSJON)}` | |
), | |
}); | |
}, | |
{ | |
urls: [ | |
'https://abc123example.execute-api.eu-west-2.amazonaws.com/v1/oauth/redirect*', | |
], | |
}, | |
['responseHeaders'] | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment