mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-27 12:36:14 +01:00
auto-fill basic auth prompts
This commit is contained in:
parent
01e48377e9
commit
41c32f3874
@ -2,7 +2,8 @@ var isBackground = true,
|
||||
loginToAutoFill = null,
|
||||
pageDetailsToAutoFill = [],
|
||||
autofillTimeout = null,
|
||||
menuOptionsLoaded = [];
|
||||
menuOptionsLoaded = [],
|
||||
pendingAuthRequests = [];
|
||||
|
||||
var bg_loginsToAdd = [];
|
||||
|
||||
@ -209,6 +210,72 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) {
|
||||
}
|
||||
});
|
||||
|
||||
chrome.webRequest.onAuthRequired.addListener(function (details, callback) {
|
||||
if (!details.url || pendingAuthRequests.indexOf(details.requestId) != -1) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var domain = bg_utilsService.getDomain(details.url);
|
||||
if (!domain) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
pendingAuthRequests.push(details.requestId);
|
||||
|
||||
if (bg_utilsService.isFirefox()) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) {
|
||||
if (!logins || logins.length !== 1) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
authCredentials: {
|
||||
username: logins[0].username,
|
||||
password: logins[0].password
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
else {
|
||||
bg_loginService.getAllDecryptedForDomain(domain).then(function (logins) {
|
||||
if (!logins || logins.length !== 1) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
callback({
|
||||
authCredentials: {
|
||||
username: logins[0].username,
|
||||
password: logins[0].password
|
||||
}
|
||||
});
|
||||
}, function () {
|
||||
callback();
|
||||
});
|
||||
}
|
||||
}, { urls: ['http://*/*'] }, [bg_utilsService.isFirefox() ? 'blocking' : 'asyncBlocking']);
|
||||
|
||||
chrome.webRequest.onCompleted.addListener(completeAuthRequest, { urls: ['http://*/*'] });
|
||||
chrome.webRequest.onErrorOccurred.addListener(completeAuthRequest, { urls: ['http://*/*'] });
|
||||
|
||||
function completeAuthRequest(details) {
|
||||
var i = pendingAuthRequests.indexOf(details.requestId);
|
||||
if (i > -1) {
|
||||
pendingAuthRequests.splice(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
var buildingContextMenu = false;
|
||||
function buildContextMenu(callback) {
|
||||
if (buildingContextMenu) {
|
||||
|
@ -72,7 +72,9 @@
|
||||
"clipboardWrite",
|
||||
"idle",
|
||||
"http://*/*",
|
||||
"https://*/*"
|
||||
"https://*/*",
|
||||
"webRequest",
|
||||
"webRequestBlocking"
|
||||
],
|
||||
"commands": {
|
||||
"autofill_login": {
|
||||
|
@ -228,13 +228,12 @@ function initAutofill() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.loginService.getAllDecryptedForDomain(tabDomain).then(function (logins) {
|
||||
if (!logins.length) {
|
||||
self.loginService.getLastUsedForDomain(tabDomain).then(function (login) {
|
||||
if (!login) {
|
||||
return;
|
||||
}
|
||||
|
||||
var sortedLogins = logins.sort(self.loginService.sortLoginsByLastUsed);
|
||||
self.doAutoFill(sortedLogins[0], pageDetails, true, true, true);
|
||||
|
||||
self.doAutoFill(login, pageDetails, true, true, true);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
@ -193,6 +193,21 @@ function initLoginService() {
|
||||
});
|
||||
};
|
||||
|
||||
LoginService.prototype.getLastUsedForDomain = function (domain) {
|
||||
var self = this;
|
||||
var deferred = Q.defer();
|
||||
self.getAllDecryptedForDomain(domain).then(function (logins) {
|
||||
if (!logins.length) {
|
||||
deferred.reject();
|
||||
return;
|
||||
}
|
||||
|
||||
var sortedLogins = logins.sort(self.sortLoginsByLastUsed);
|
||||
deferred.resolve(sortedLogins[0]);
|
||||
});
|
||||
return deferred.promise;
|
||||
};
|
||||
|
||||
LoginService.prototype.saveWithServer = function (login) {
|
||||
var deferred = Q.defer();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user