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

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

Issue 687873003: Allow the background page to get an OAuth token for apps v1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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/it2me_helpee_channel.js
diff --git a/remoting/webapp/crd/js/it2me_helpee_channel.js b/remoting/webapp/crd/js/it2me_helpee_channel.js
index b53f79858fc635d9bdff346bd190046cfc9bd857..ed0ff49d289dce562cf4098c1fb7619c0bf9de57 100644
--- a/remoting/webapp/crd/js/it2me_helpee_channel.js
+++ b/remoting/webapp/crd/js/it2me_helpee_channel.js
@@ -374,23 +374,39 @@ remoting.It2MeHelpeeChannel.prototype.initializeHost_ = function() {
};
/**
- * TODO(kelvinp): The existing implementation only works in the v2 app
- * We need to implement token fetching for the v1 app using remoting.OAuth2
- * before launch (crbug.com/405130).
- *
* @return {Promise} Promise that resolves with the OAuth token as the value.
*/
remoting.It2MeHelpeeChannel.prototype.fetchOAuthToken_ = function() {
- if (!base.isAppsV2()) {
- throw new Error('fetchOAuthToken_ is not implemented in the v1 app.');
+ if (base.isAppsV2()) {
+ /**
+ * @param {function(*=):void} resolve
+ */
+ return new Promise(function(resolve){
+ // TODO(jamiewalch): Make this work with {interactive: true} as well.
+ chrome.identity.getAuthToken({ 'interactive': false }, resolve);
+ });
+ } else {
+ /**
+ * @param {function(*=):void} resolve
+ */
+ return new Promise(function(resolve) {
+ /** @type {remoting.OAuth2} */
+ var oauth2 = new remoting.OAuth2();
+ var onAuthenticated = function() {
+ oauth2.callWithToken(
+ resolve,
+ function() { throw new Error('Authentication failed.'); });
+ };
+ /** @param {remoting.Error} error */
+ var onError = function(error) {
+ if (error != remoting.Error.NOT_AUTHENTICATED) {
+ throw new Error('Unexpected error fetch auth token: ' + error);
+ }
+ oauth2.doAuthRedirect(onAuthenticated);
+ };
+ oauth2.callWithToken(resolve, onError);
+ });
}
-
- /**
- * @param {function(*=):void} resolve
- */
- return new Promise(function(resolve){
- chrome.identity.getAuthToken({ 'interactive': false }, resolve);
- });
};
/**

Powered by Google App Engine
This is Rietveld 408576698