Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Unified Diff: remoting/webapp/crd/js/oauth2.js

Issue 868203002: Handle authentication failures in the v2 app by restarting the app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address reviewer's feedback Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/crd/js/oauth2.js
diff --git a/remoting/webapp/crd/js/oauth2.js b/remoting/webapp/crd/js/oauth2.js
index 52e12f8841480cf92bb92a8b2d7e274289e2e1cd..77d53234b93a63d980badeed28c17bf398ba2caf 100644
--- a/remoting/webapp/crd/js/oauth2.js
+++ b/remoting/webapp/crd/js/oauth2.js
@@ -292,21 +292,35 @@ remoting.OAuth2.prototype.getAuthorizationCode = function(onDone) {
/**
* Redirect page to get a new OAuth Refresh Token.
*
- * @param {function():void} onDone Completion callback.
- * @return {void} Nothing.
+ * @return {Promise} A promise that resolves when the token is received.
*/
-remoting.OAuth2.prototype.doAuthRedirect = function(onDone) {
+remoting.OAuth2.prototype.handleAuthFailure = function() {
+ var deferred = new base.Deferred();
+
/** @type {remoting.OAuth2} */
var that = this;
/** @param {?string} code */
var onAuthorizationCode = function(code) {
if (code) {
- that.exchangeCodeForToken(code, onDone);
+ that.exchangeCodeForToken(code, deferred.resolve.bind(deferred));
} else {
- onDone();
+ deferred.reject(remoting.Error.NOT_AUTHENTICATED);
}
};
this.getAuthorizationCode(onAuthorizationCode);
+
+ return deferred.promise();
+};
+
+/**
+ * Removes the cached token, prompts the user to get the new token and
+ * relaunches the current window.
+ * @return {void} Nothing.
+ */
+remoting.OAuth2.prototype.handleAuthFailureAndRelaunch = function() {
+ this.handleAuthFailure().then(function() {
+ window.location.reload();
+ });
};
/**

Powered by Google App Engine
This is Rietveld 408576698