Index: remoting/webapp/crd/js/identity.js |
diff --git a/remoting/webapp/crd/js/identity.js b/remoting/webapp/crd/js/identity.js |
index aef0f2c6f984444844d7002e1f4d827a90dfb09b..dbf476ca4b49d60e26911458072f8c7d06e57af4 100644 |
--- a/remoting/webapp/crd/js/identity.js |
+++ b/remoting/webapp/crd/js/identity.js |
@@ -35,6 +35,8 @@ remoting.Identity = function(consentCallback) { |
this.fullName_ = ''; |
/** @type {Array.<remoting.Identity.Callbacks>} */ |
this.pendingCallbacks_ = []; |
+ /** @type {Promise} */ |
+ this.handleAuthFailurePromise_ = null; |
}; |
/** |
@@ -75,18 +77,59 @@ remoting.Identity.prototype.callWithNewToken = function(onOk, onError) { |
chrome.identity.removeCachedAuthToken( |
{'token': token }, |
that.callWithToken.bind(that, onOk, onError)); |
- }; |
+ } |
this.callWithToken(revokeToken, onError); |
}; |
/** |
+ * Removes the cached token and prompts the user to get a new one. |
+ * @return {Promise} A promise that resolves when a new token is fetched. |
+ */ |
+remoting.Identity.prototype.handleAuthFailure = function() { |
+ if (!this.handleAuthFailurePromise_) { |
+ var that = this; |
+ |
+ var revokeToken = base.Promise.as(this.removeCachedAuthToken_, []); |
Jamie
2015/01/23 23:33:27
Using Promise.as to Promisify an API we own is a l
kelvinp
2015/01/28 00:26:46
Agreed. I have converted the private API (removeCa
|
+ |
+ this.handleAuthFailurePromise_= revokeToken.then(function() { |
+ return base.Promise.as(that.consentCallback_, []); |
+ }).then(function(){ |
+ return base.Promise.as( |
+ chrome.identity.getAuthToken, [{ 'interactive': true }]); |
+ }).then( |
+ /** @param {string} token */ |
+ function(token) { |
+ that.handleAuthFailurePromise_ = null; |
+ if (token) { |
+ return Promise.resolve(token); |
+ } |
+ return Promise.reject(remoting.Error.NOT_AUTHENTICATED); |
+ } |
+ ); |
+ } |
+ return this.handleAuthFailurePromise_; |
+}; |
+ |
+/** |
+ * Removes the cached token, prompts the user to get a new one and |
+ * relaunches the current window. |
+ * @return {void} Nothing. |
+ */ |
+remoting.Identity.prototype.handleAuthFailureAndRelaunch = function() { |
+ this.handleAuthFailure().then(function() { |
+ base.RemoteMethods.invoke(remoting.ActivationHandler.Request.RELAUNCH, |
+ [chrome.app.window.current().id]); |
+ }); |
+}; |
+ |
+/** |
* Remove the cached auth token, if any. |
* |
* @param {function():void} onDone Completion callback. |
* @return {void} Nothing. |
*/ |
-remoting.Identity.prototype.removeCachedAuthToken = function(onDone) { |
+remoting.Identity.prototype.removeCachedAuthToken_ = function(onDone) { |
Jamie
2015/01/23 23:33:27
Underscore and @private should go hand-in-hand. Pl
kelvinp
2015/01/28 00:26:46
Done.
|
/** @param {string} token */ |
var onToken = function(token) { |
if (token) { |