Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
for http auth, if multiple credentials, wait until a user selects cre…
Browse files Browse the repository at this point in the history
…dentials from the popup. fixes #41
  • Loading branch information
smorks committed Nov 21, 2017
1 parent 43e8d21 commit 701e196
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
28 changes: 10 additions & 18 deletions src/background/httpauth.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var httpAuth = httpAuth || {};

httpAuth.requests = {};
httpAuth.requests = [];

httpAuth.requestCompleted = function (details) {
var req = httpAuth.requests[details.requestId];
if (req) {
delete httpAuth.requests[details.requestId];
var idx = httpAuth.requests.indexOf(details.requestId);
if (idx >= 0) {
httpAuth.requests.splice(idx, 1);
}
}

Expand All @@ -21,16 +21,12 @@ httpAuth.handleRequestCallback = function (details, callback) {

httpAuth.processPendingCallbacks = function (details, resolve, reject) {

if (!page.tabs[details.tabId]) {
if (httpAuth.requests.indexOf(details.requestId) >= 0 || !page.tabs[details.tabId]) {
reject({});
return;
}

var creds = httpAuth.requests[details.requestId];
if (creds) {
httpAuth.loginOrShowCredentials(creds, details, resolve, reject);
return;
}
httpAuth.requests.push(details.requestId);

if (details.challenger) {
details.proxyUrl = details.challenger.host;
Expand All @@ -46,19 +42,15 @@ httpAuth.processPendingCallbacks = function (details, resolve, reject) {
httpAuth.loginOrShowCredentials = function (logins, details, resolve, reject) {
// at least one login found --> use first to login
if (logins.length > 0) {
cipevent.onHTTPAuthPopup(null, { "id": details.tabId }, { "logins": logins, "url": details.searchUrl });
//generate popup-list for HTTP Auth usernames + descriptions
if (page.settings.autoFillAndSend) {
var creds = logins.shift();
httpAuth.requests[details.requestId] = logins;
if (logins.length == 1 && page.settings.autoFillAndSend) {
resolve({
authCredentials: {
username: creds.Login,
password: creds.Password
username: logins[0].Login,
password: logins[0].Password
}
});
} else {
reject({});
cipevent.onHTTPAuthPopup(null, { "id": details.tabId }, { "logins": logins, "url": details.searchUrl, 'resolve': resolve });
}
}
// no logins found
Expand Down
20 changes: 14 additions & 6 deletions src/popups/popup_httpauth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$(function() {
browser.runtime.getBackgroundPage().then(function(global) {
browser.tabs.query({"active": true, "currentWindow": true}).then(function(tabs) {
$(function () {
browser.runtime.getBackgroundPage().then(function (global) {
browser.tabs.query({ "active": true, "currentWindow": true }).then(function (tabs) {
//var data = global.tab_httpauth_list["tab" + tab.id];
var tab = tabs[0];
var data = global.page.tabs[tab.id].loginList;
Expand All @@ -10,9 +10,17 @@ $(function() {
var a = document.createElement("a");
a.textContent = data.logins[i].Login + " (" + data.logins[i].Name + ")";
li.appendChild(a);
$(a).data("url", data.url.replace(/:\/\//g, "://" + data.logins[i].Login + ":" + data.logins[i].Password + "@"));
$(a).click(function() {
browser.tabs.update(tab.id, {"url": $(this).data("url")});
$(a).data('creds', data.logins[i]);
$(a).click(function () {
if (data.resolve) {
var creds = $(this).data('creds');
data.resolve({
authCredentials: {
username: creds.Login,
password: creds.Password
}
});
}
close();
});
ul.appendChild(li);
Expand Down

0 comments on commit 701e196

Please sign in to comment.