Chromium Code Reviews| 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..58115e15f54a0f9e2694af66efe974df19379d71 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); |
| }; |
| @@ -206,19 +219,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() { |
|
Jamie
2015/01/29 01:52:34
I really like this new Promise-based approach. As
kelvinp
2015/01/29 19:40:31
Courage replied. Turns out the user interaction i
|
| + chrome.identity.getAuthToken({'interactive': true}, |
| + that.onAuthComplete_.bind(that, true)); |
| + }); |
| }; |
| /** |