Change: switch to launchWebAuthFlow polyfill (#1017)
* WIP: add webextLaunchWebAuthFlow * Change: switch to webextLaunchWebAuthFlow * Bump dependencies * Fix: use minimized version * Fix: wrong call to promisifyChrome
This commit is contained in:
parent
01cfb435f6
commit
07ba44cc2c
|
@ -1,10 +1,11 @@
|
|||
/* global chromeLocal promisifyChrome FIREFOX */
|
||||
/* global chromeLocal promisifyChrome webextLaunchWebAuthFlow FIREFOX */
|
||||
/* exported tokenManager */
|
||||
'use strict';
|
||||
|
||||
const tokenManager = (() => {
|
||||
promisifyChrome({
|
||||
identity: ['launchWebAuthFlow'],
|
||||
'windows': ['create', 'update', 'remove'],
|
||||
'tabs': ['create', 'update', 'remove']
|
||||
});
|
||||
const AUTH = {
|
||||
dropbox: {
|
||||
|
@ -160,9 +161,10 @@ const tokenManager = (() => {
|
|||
Object.assign(query, provider.authQuery);
|
||||
}
|
||||
const url = `${provider.authURL}?${stringifyQuery(query)}`;
|
||||
return browser.identity.launchWebAuthFlow({
|
||||
return webextLaunchWebAuthFlow({
|
||||
url,
|
||||
interactive
|
||||
interactive,
|
||||
redirect_uri: query.redirect_uri
|
||||
})
|
||||
.then(url => {
|
||||
const params = new URLSearchParams(
|
||||
|
@ -185,7 +187,7 @@ const tokenManager = (() => {
|
|||
code,
|
||||
grant_type: 'authorization_code',
|
||||
client_id: provider.clientId,
|
||||
redirect_uri: provider.redirect_uri || chrome.identity.getRedirectURL()
|
||||
redirect_uri: query.redirect_uri
|
||||
};
|
||||
if (provider.clientSecret) {
|
||||
body.client_secret = provider.clientSecret;
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
"vendor/semver-bundle/semver.js",
|
||||
"vendor/db-to-cloud/db-to-cloud.min.js",
|
||||
"vendor/uuid/uuid.min.js",
|
||||
"vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min.js",
|
||||
"background/token-manager.js",
|
||||
"background/sync.js",
|
||||
"background/content-scripts.js",
|
||||
|
|
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -7934,6 +7934,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"webext-launch-web-auth-flow": {
|
||||
"version": "0.1.0",
|
||||
"resolved": "https://registry.npmjs.org/webext-launch-web-auth-flow/-/webext-launch-web-auth-flow-0.1.0.tgz",
|
||||
"integrity": "sha512-3W8ANT9/6uL6NX5SiaKQee439dfiS1NT8wSc+vmjly/2MmH7FBqGFBXLfBFw296w8OOqHNPnEdNcBkDGJQkDgg=="
|
||||
},
|
||||
"webext-tx-fix": {
|
||||
"version": "0.3.3",
|
||||
"resolved": "https://registry.npmjs.org/webext-tx-fix/-/webext-tx-fix-0.3.3.tgz",
|
||||
|
|
|
@ -15,7 +15,8 @@
|
|||
"stylelint-bundle": "^8.0.0",
|
||||
"stylus-lang-bundle": "^0.54.5",
|
||||
"usercss-meta": "^0.9.0",
|
||||
"uuid": "^8.1.0"
|
||||
"uuid": "^8.1.0",
|
||||
"webext-launch-web-auth-flow": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"archiver": "^4.0.1",
|
||||
|
|
|
@ -62,6 +62,9 @@ const files = {
|
|||
],
|
||||
'uuid': [
|
||||
'dist/umd/uuidv4.min.js → uuid.min.js'
|
||||
],
|
||||
'webext-launch-web-auth-flow': [
|
||||
'dist/webext-launch-web-auth-flow.min.js → webext-launch-web-auth-flow.min.js'
|
||||
]
|
||||
};
|
||||
|
||||
|
|
22
vendor/webext-launch-web-auth-flow/LICENSE
vendored
Normal file
22
vendor/webext-launch-web-auth-flow/LICENSE
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 eight
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
5
vendor/webext-launch-web-auth-flow/README.md
vendored
Normal file
5
vendor/webext-launch-web-auth-flow/README.md
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
## webext-launch-web-auth-flow v0.1.0
|
||||
|
||||
Following files are copied from npm (node_modules):
|
||||
|
||||
* webext-launch-web-auth-flow.min.js: dist\webext-launch-web-auth-flow.min.js
|
2
vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min.js
vendored
Normal file
2
vendor/webext-launch-web-auth-flow/webext-launch-web-auth-flow.min.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
var webextLaunchWebAuthFlow=function(){"use strict";function e(e,r,t,n,o,i,s){try{var u=e[i](s),a=u.value}catch(e){return void t(e)}u.done?r(a):Promise.resolve(a).then(n,o)}function r(r){return function(){var t=this,n=arguments;return new Promise((function(o,i){var s=r.apply(t,n);function u(r){e(s,o,i,u,a,"next",r)}function a(r){e(s,o,i,u,a,"throw",r)}u(void 0)}))}}function t(e){return n.apply(this,arguments)}function n(){return(n=r((function*(e){if(browser.windows)return yield browser.windows.create(e);const r={active:"minimized"!==e.state,url:e.url};return{tabs:[yield browser.tabs.create(r)]}}))).apply(this,arguments)}function o(e,r,t){return i.apply(this,arguments)}function i(){return(i=r((function*(e,r,t){return e?yield browser.windows.update(e,t):yield browser.tabs.update(r,{active:t.focused})}))).apply(this,arguments)}function s(e,r){return u.apply(this,arguments)}function u(){return(u=r((function*(e,r){return e?yield browser.windows.remove(e):yield browser.tabs.remove(r)}))).apply(this,arguments)}function a(){const e={};return e.promise=new Promise((r,t)=>{e.resolve=r,e.reject=t}),e}function c(){return(c=r((function*({url:e,redirect_uri:r,interactive:n=!1}){const i=yield t({type:"popup",url:e,state:"minimized"}),u=i.id,c=i.tabs[0].id,d=a(),l=d.promise,w=d.resolve,b=d.reject;browser.webRequest.onBeforeRequest.addListener(f,{urls:["*://*/*"],tabId:c,types:["main_frame"]},["blocking"]),browser.webNavigation.onDOMContentLoaded.addListener(p),browser.tabs.onRemoved.addListener(v);try{return yield l}finally{browser.webRequest.onBeforeRequest.removeListener(f),browser.webNavigation.onDOMContentLoaded.removeListener(p),browser.tabs.onRemoved.removeListener(v),s(u,c).catch(e=>console.error(e))}function f(e){if(!e.frameId&&e.tabId===c&&e.url.startsWith(r))return w(e.url),{cancel:!0}}function p(e){e.frameId||e.tabId!==c||(n?o(u,c,{focused:!0,state:"normal"}).catch(e=>console.error(e)):b(new Error("User interaction required")),browser.webNavigation.onDOMContentLoaded.removeListener(p))}function v(e){e===c&&b(new Error("Canceled by user"))}}))).apply(this,arguments)}return function(e){return c.apply(this,arguments)}}();
|
||||
//# sourceMappingURL=webext-launch-web-auth-flow.min.js.map
|
Loading…
Reference in New Issue
Block a user