Fixed Google different oauth scopes after refresh

This commit is contained in:
benweet 2013-10-15 23:45:42 +01:00
parent ffd9953d59
commit 6af6a70f75
7 changed files with 74 additions and 43 deletions

View File

@ -1,5 +1,5 @@
CACHE MANIFEST CACHE MANIFEST
#Date Tue Oct 15 2013 01:02:10 #Date Tue Oct 15 2013 23:44:34
CACHE: CACHE:
index.html index.html

View File

@ -13662,7 +13662,7 @@ define("config", function() {}), define("storage", [ "underscore", "utils" ], fu
} }
}), t; }), t;
}), define("text!html/settingsExtensionsAccordion.html", [], function() { }), define("text!html/settingsExtensionsAccordion.html", [], function() {
return '<div class="panel">\n <div class="accordion-heading">\n <div class="checkbox pull-right">\n <label> <input id="input-enable-extension-<%= extensionId %>"\n type="checkbox"<% if(!isOptional) print(\'disabled\') %>>\n enabled\n </label>\n </div>\n <span data-toggle="collapse" data-parent=".accordion-extensions"\n class="accordion-toggle" href="#accordion-extensions-collapse-<%= extensionId %>">\n <%= extensionName %> </span>\n </div>\n <div id="accordion-extensions-collapse-<%= extensionId %>" class="collapse">\n <div class="accordion-inner clearfix"><%= settingsBlock %></div>\n </div>\n</div>\n'; return '<div class="panel">\n <div class="accordion-heading">\n <div class="checkbox pull-right">\n <label> <input id="input-enable-extension-<%= extensionId %>"\n type="checkbox"<% if(!isOptional) print(\'disabled\') %>>\n enabled\n </label>\n </div>\n <a data-toggle="collapse" data-parent=".accordion-extensions"\n class="accordion-toggle" href="#accordion-extensions-collapse-<%= extensionId %>">\n <%= extensionName %> </a>\n </div>\n <div id="accordion-extensions-collapse-<%= extensionId %>" class="collapse">\n <div class="accordion-inner clearfix"><%= settingsBlock %></div>\n </div>\n</div>\n';
}), function() { }), function() {
var e = function(e, t, n, i) { var e = function(e, t, n, i) {
this.rawMessage = e, this.parsedLine = void 0 !== t ? t : -1, this.snippet = void 0 !== n ? n : null, this.rawMessage = e, this.parsedLine = void 0 !== t ? t : -1, this.snippet = void 0 !== n ? n : null,
@ -20364,13 +20364,13 @@ if (hljs.LANGUAGES.glsl = function(e) {
var u = void 0; var u = void 0;
return c.onPagedownConfigure = function(e) { return c.onPagedownConfigure = function(e) {
u = document.getElementById("preview-contents"); u = document.getElementById("preview-contents");
var n = document.querySelectorAll(".table-of-contents"), i = new RegExp("^" + c.config.marker + "$", "g"); var n = new RegExp("^" + c.config.marker + "$", "g");
e.hooks.chain("onPreviewRefresh", function() { e.hooks.chain("onPreviewRefresh", function() {
var e = l(); var e = document.querySelectorAll(".table-of-contents, .toc"), i = l();
t.each(u.getElementsByTagName("p"), function(t) { t.each(u.getElementsByTagName("p"), function(e) {
i.test(t.innerHTML) && (t.innerHTML = e); n.test(e.innerHTML) && (e.innerHTML = i);
}), t.each(n, function(t) { }), t.each(e, function(e) {
t.innerHTML = e; e.innerHTML = i;
}); });
}); });
}, c; }, c;
@ -26926,32 +26926,32 @@ if (hljs.LANGUAGES.glsl = function(e) {
}), void 0); }), void 0);
}); });
} }
function l(t, i) { function l(t, i, o) {
t.onRun(function() { t.onRun(function() {
function o() { function r() {
n.redirectConfirm("You are being redirected to <strong>Google</strong> authorization page.", function() { n.redirectConfirm("You are being redirected to <strong>Google</strong> authorization page.", function() {
t.chain(r); t.chain(s);
}, function() { }, function() {
t.error(new Error("Operation canceled.")); t.error(new Error("Operation canceled."));
}); });
} }
function r() { function s() {
s === !1 && (t.timeout = ASYNC_TASK_LONG_TIMEOUT); a === !1 && (t.timeout = ASYNC_TASK_LONG_TIMEOUT);
var n = e.chain(g).pick(e.keys(h).concat([ i ])).flatten().value(); var n = e.chain(g).pick(h.getListWithNew(i)).flatten().value();
gapi.auth.authorize({ gapi.auth.authorize({
client_id: GOOGLE_CLIENT_ID, client_id: GOOGLE_CLIENT_ID,
scope: n, scope: n,
immediate: s immediate: a
}, function(e) { }, function(e) {
gapi.client.load("drive", "v2", function() { gapi.client.load("drive", "v2", function() {
return !e || e.error ? d === !0 && s === !0 ? (s = !1, t.chain(o), void 0) : (t.error(new Error("Access to Google account is not authorized.")), return !e || e.error ? d === !0 && a === !0 ? (a = !1, t.chain(r), void 0) : (t.error(new Error("Access to Google account is not authorized.")),
void 0) : (h[i] = !0, t.chain(), void 0); void 0) : (h.add(i), t.chain(), void 0);
}); });
}); });
} }
if (e.has(h, i)) return t.chain(), void 0; if (!o && h.isAuthorized(i)) return t.chain(), void 0;
var s = !0; var a = !0;
t.chain(r); t.chain(s);
}); });
} }
function c(e, t) { function c(e, t) {
@ -26959,9 +26959,9 @@ if (hljs.LANGUAGES.glsl = function(e) {
if (e) if (logger.error(e), "string" == typeof e) i = e; else { if (e) if (logger.error(e), "string" == typeof e) i = e; else {
if (i = "Google error (" + e.code + ": " + e.message + ").", e.code >= 500 && e.code < 600) return t.retry(new Error(i)), if (i = "Google error (" + e.code + ": " + e.message + ").", e.code >= 500 && e.code < 600) return t.retry(new Error(i)),
void 0; void 0;
if (401 === e.code || 403 === e.code || "token_refresh_required" == e.code) return h = {}, if (401 === e.code || 403 === e.code || "token_refresh_required" == e.code) return h.reset(),
i = "Access to Google account is not authorized.", t.retry(new Error(i), 1), void 0; i = "Access to Google account is not authorized.", t.retry(new Error(i), 1), void 0;
(0 === e.code || -1 === e.code) && (d = !1, h = {}, n.setOffline(), i = "|stopPublish"); (0 === e.code || -1 === e.code) && (d = !1, h.reset(), n.setOffline(), i = "|stopPublish");
} }
t.error(new Error(i)); t.error(new Error(i));
} }
@ -26989,7 +26989,23 @@ if (hljs.LANGUAGES.glsl = function(e) {
}), void 0); }), void 0);
}); });
} }
var d = !1, h = {}, p = {}, f = !1; var d = !1, h = {};
(function() {
var t = {}, n = !1;
e.each((localStorage.gdrivePermissions || "").split(";"), function(e) {
e && (t[e] = !0);
}), h.reset = function() {
n = !1;
}, h.isAuthorized = function(i) {
return n && e.has(t, i);
}, h.add = function(i) {
t[i] = !0, localStorage.gdrivePermissions = e.keys(t).join(";"), n = !0;
}, h.getListWithNew = function(n) {
var i = e.keys(t);
return e.has(t, n) || i.push(n), i;
};
})();
var p = {}, f = !1;
r.addListener("onOfflineChanged", function(e) { r.addListener("onOfflineChanged", function(e) {
f = e; f = e;
}); });
@ -26999,9 +27015,8 @@ if (hljs.LANGUAGES.glsl = function(e) {
picasa: [ "https://picasaweb.google.com/data/" ] picasa: [ "https://picasaweb.google.com/data/" ]
}; };
p.forceGdriveAuthenticate = function() { p.forceGdriveAuthenticate = function() {
h = e.omit(h, "gdrive"); var e = new s();
var t = new s(); a(e), l(e, "gdrive", !0), e.enqueue();
a(t), l(t, "gdrive"), t.enqueue();
}, p.upload = function(e, t, n, o, r, u, d) { }, p.upload = function(e, t, n, o, r, u, d) {
var h = void 0, p = new s(); var h = void 0, p = new s();
a(p), l(p, "gdrive"), p.onRun(function() { a(p), l(p, "gdrive"), p.onRun(function() {

View File

@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo
.modal-settings textarea{max-width:100%;min-height:100px} .modal-settings textarea{max-width:100%;min-height:100px}
.modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #f0f3f4;-webkit-box-shadow:none;box-shadow:none} .modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #f0f3f4;-webkit-box-shadow:none;box-shadow:none}
.modal-settings .accordion-heading{padding:12px 15px} .modal-settings .accordion-heading{padding:12px 15px}
.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer}
.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline}
.modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0}
.modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px}
.modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left}

View File

@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo
.modal-settings textarea{max-width:100%;min-height:100px} .modal-settings textarea{max-width:100%;min-height:100px}
.modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #f1f1f1;-webkit-box-shadow:none;box-shadow:none} .modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #f1f1f1;-webkit-box-shadow:none;box-shadow:none}
.modal-settings .accordion-heading{padding:12px 15px} .modal-settings .accordion-heading{padding:12px 15px}
.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer}
.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline}
.modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0}
.modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px}
.modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left}

View File

@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo
.modal-settings textarea{max-width:100%;min-height:100px} .modal-settings textarea{max-width:100%;min-height:100px}
.modal-settings .panel{border:0;border-radius:inherit;background:#323232;border-bottom:1px solid #444444;-webkit-box-shadow:none;box-shadow:none} .modal-settings .panel{border:0;border-radius:inherit;background:#323232;border-bottom:1px solid #444444;-webkit-box-shadow:none;box-shadow:none}
.modal-settings .accordion-heading{padding:12px 15px} .modal-settings .accordion-heading{padding:12px 15px}
.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer}
.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline}
.modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0}
.modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px}
.modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left}

View File

@ -1546,8 +1546,6 @@ a{-webkit-transition:background-color ease-in-out .15s,color ease-in-out .15s,bo
.modal-settings textarea{max-width:100%;min-height:100px} .modal-settings textarea{max-width:100%;min-height:100px}
.modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #ede9e6;-webkit-box-shadow:none;box-shadow:none} .modal-settings .panel{border:0;border-radius:inherit;background:#ffffff;border-bottom:1px solid #ede9e6;-webkit-box-shadow:none;box-shadow:none}
.modal-settings .accordion-heading{padding:12px 15px} .modal-settings .accordion-heading{padding:12px 15px}
.modal-settings .accordion-heading .accordion-toggle{display:inline;padding:0;font-weight:bold;cursor:pointer}
.modal-settings .accordion-heading .accordion-toggle:hover{text-decoration:underline}
.modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0} .modal-settings .accordion-heading .checkbox{margin-top:0;margin-bottom:0}
.modal-settings .accordion-inner{border:0;padding:10px 40px 20px} .modal-settings .accordion-inner{border:0;padding:10px 40px 20px}
.modal-settings .accordion-inner .form-horizontal .control-label{text-align:left} .modal-settings .accordion-inner .form-horizontal .control-label{text-align:left}

View File

@ -10,7 +10,32 @@ define([
], function(_, $, core, utils, settings, eventMgr, AsyncTask) { ], function(_, $, core, utils, settings, eventMgr, AsyncTask) {
var connected = false; var connected = false;
var permissionList = {}; var authorizationMgr = {};
(function() {
var permissionList = {};
var isAuthorized = false;
_.each((localStorage.gdrivePermissions || '').split(';'), function(permission) {
permission && (permissionList[permission] = true);
});
authorizationMgr.reset = function() {
isAuthorized = false;
};
authorizationMgr.isAuthorized = function(permission) {
return isAuthorized && _.has(permissionList, permission);
};
authorizationMgr.add = function(permission) {
permissionList[permission] = true;
localStorage.gdrivePermissions = _.keys(permissionList).join(';');
isAuthorized = true;
};
authorizationMgr.getListWithNew = function(permission) {
var result = _.keys(permissionList);
if(!_.has(permissionList, permission)) {
result.push(permission);
}
return result;
};
})();
var googleHelper = {}; var googleHelper = {};
@ -65,9 +90,9 @@ define([
'https://picasaweb.google.com/data/' 'https://picasaweb.google.com/data/'
] ]
}; };
function authenticate(task, permission) { function authenticate(task, permission, force) {
task.onRun(function() { task.onRun(function() {
if(_.has(permissionList, permission)) { if(!force && authorizationMgr.isAuthorized(permission)) {
task.chain(); task.chain();
return; return;
} }
@ -83,7 +108,7 @@ define([
if(immediate === false) { if(immediate === false) {
task.timeout = ASYNC_TASK_LONG_TIMEOUT; task.timeout = ASYNC_TASK_LONG_TIMEOUT;
} }
var scopeList = _.chain(scopeMap).pick(_.keys(permissionList).concat([permission])).flatten().value(); var scopeList = _.chain(scopeMap).pick(authorizationMgr.getListWithNew(permission)).flatten().value();
gapi.auth.authorize({ gapi.auth.authorize({
'client_id': GOOGLE_CLIENT_ID, 'client_id': GOOGLE_CLIENT_ID,
'scope': scopeList, 'scope': scopeList,
@ -103,7 +128,7 @@ define([
return; return;
} }
// Success // Success
permissionList[permission] = true; authorizationMgr.add(permission);
task.chain(); task.chain();
}); });
}); });
@ -112,10 +137,9 @@ define([
}); });
} }
googleHelper.forceGdriveAuthenticate = function() { googleHelper.forceGdriveAuthenticate = function() {
permissionList = _.omit(permissionList, 'gdrive') ;
var task = new AsyncTask(); var task = new AsyncTask();
connect(task); connect(task);
authenticate(task, 'gdrive'); authenticate(task, 'gdrive', true);
task.enqueue(); task.enqueue();
}; };
@ -572,14 +596,14 @@ define([
return; return;
} }
else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") { else if(error.code === 401 || error.code === 403 || error.code == "token_refresh_required") {
permissionList = {}; authorizationMgr.reset();
errorMsg = "Access to Google account is not authorized."; errorMsg = "Access to Google account is not authorized.";
task.retry(new Error(errorMsg), 1); task.retry(new Error(errorMsg), 1);
return; return;
} }
else if(error.code === 0 || error.code === -1) { else if(error.code === 0 || error.code === -1) {
connected = false; connected = false;
permissionList = {}; authorizationMgr.reset();
core.setOffline(); core.setOffline();
errorMsg = "|stopPublish"; errorMsg = "|stopPublish";
} }