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

Unified Diff: remoting/webapp/crd/js/identity.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: Rebase 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
« no previous file with comments | « remoting/webapp/crd/js/host_list.js ('k') | remoting/webapp/crd/js/it2me_helpee_channel.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0421410448a5ce7660487b695d1a6b541ecc0e50 100644
--- a/remoting/webapp/crd/js/identity.js
+++ b/remoting/webapp/crd/js/identity.js
@@ -16,19 +16,17 @@ var remoting = remoting || {};
* TODO(jamiewalch): Remove remoting.OAuth2 from this type annotation when
* the Apps v2 work is complete.
*
- * @type {remoting.Identity|remoting.OAuth2}
+ * @type {remoting.Identity}
*/
remoting.identity = null;
/**
- * @param {function(function():void):void} consentCallback Callback invoked if
- * user consent is required. The callback is passed a continuation function
- * which must be called from an interactive event handler (e.g. "click").
+ * @param {remoting.Identity.ConsentDialog} consentDialog
* @constructor
*/
-remoting.Identity = function(consentCallback) {
+remoting.Identity = function(consentDialog) {
/** @private */
- this.consentCallback_ = consentCallback;
+ this.consentDialog_ = consentDialog;
/** @type {string} @private */
this.email_ = '';
/** @type {string} @private */
@@ -38,6 +36,21 @@ remoting.Identity = function(consentCallback) {
};
/**
+ * chrome.identity.getAuthToken must be initiated from user interactions if
+ * called with interactive equals true. This interface prompts a dialog for
+ * the user's consent.
+ *
+ * @interface
+ */
+remoting.Identity.ConsentDialog = function() {};
+
+/**
+ * @return {Promise} A Promise that resolves when permission to start an
+ * interactive flow is granted.
+ */
+remoting.Identity.ConsentDialog.prototype.show = function() {};
+
+/**
* Call a function with an access token.
*
* @param {function(string):void} onOk Function to invoke with access token if
@@ -75,7 +88,7 @@ remoting.Identity.prototype.callWithNewToken = function(onOk, onError) {
chrome.identity.removeCachedAuthToken(
{'token': token },
that.callWithToken.bind(that, onOk, onError));
- };
+ }
this.callWithToken(revokeToken, onError);
};
@@ -83,19 +96,21 @@ remoting.Identity.prototype.callWithNewToken = function(onOk, onError) {
/**
* Remove the cached auth token, if any.
*
- * @param {function():void} onDone Completion callback.
+ * @param {function():void=} opt_onDone Completion callback.
* @return {void} Nothing.
*/
-remoting.Identity.prototype.removeCachedAuthToken = function(onDone) {
+remoting.Identity.prototype.removeCachedAuthToken = function(opt_onDone) {
+ var onDone = (opt_onDone) ? opt_onDone : base.doNothing;
+
/** @param {string} token */
var onToken = function(token) {
if (token) {
- chrome.identity.removeCachedAuthToken({ 'token': token }, onDone);
+ chrome.identity.removeCachedAuthToken({'token': token}, onDone);
} else {
onDone();
}
};
- chrome.identity.getAuthToken({ 'interactive': false }, onToken);
+ chrome.identity.getAuthToken({'interactive': false}, onToken);
};
/**
@@ -206,19 +221,12 @@ remoting.Identity.prototype.onAuthComplete_ = function(interactive, token) {
}
// If there's no token, but we haven't yet prompted for permission, do so
- // now. The consent callback is responsible for continuing the auth flow.
- this.consentCallback_(this.onAuthContinue_.bind(this));
-};
-
-/**
- * Called in response to the user signing in to the web-app.
- *
- * @private
- */
-remoting.Identity.prototype.onAuthContinue_ = function() {
- chrome.identity.getAuthToken(
- { 'interactive': true },
- this.onAuthComplete_.bind(this, true));
+ // now.
+ var that = this;
+ this.consentDialog_.show().then(function() {
+ chrome.identity.getAuthToken({'interactive': true},
+ that.onAuthComplete_.bind(that, true));
+ });
};
/**
« no previous file with comments | « remoting/webapp/crd/js/host_list.js ('k') | remoting/webapp/crd/js/it2me_helpee_channel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698