Chromium Code Reviews| Index: remoting/webapp/crd/js/oauth2_api.js |
| diff --git a/remoting/webapp/crd/js/oauth2_api.js b/remoting/webapp/crd/js/oauth2_api.js |
| index 2bc55f5391d18b5a52eb21c24e726e2c00790510..7e5173f3eb4312dd3999881a0d545c5aea4ddafa 100644 |
| --- a/remoting/webapp/crd/js/oauth2_api.js |
| +++ b/remoting/webapp/crd/js/oauth2_api.js |
| @@ -12,50 +12,10 @@ |
| /** @suppress {duplicate} */ |
| var remoting = remoting || {}; |
| -/** @constructor */ |
| +/** @interface */ |
| remoting.OAuth2Api = function() { |
| }; |
| -/** @private |
| - * @return {string} OAuth2 token URL. |
| - */ |
| -remoting.OAuth2Api.prototype.getOAuth2TokenEndpoint_ = function() { |
| - return remoting.settings.OAUTH2_BASE_URL + '/token'; |
| -}; |
| - |
| -/** @private |
| - * @return {string} OAuth2 userinfo API URL. |
| - */ |
| -remoting.OAuth2Api.prototype.getOAuth2ApiUserInfoEndpoint_ = function() { |
| - return remoting.settings.OAUTH2_API_BASE_URL + '/v1/userinfo'; |
| -}; |
| - |
| - |
| -/** |
| - * Interprets HTTP error responses in authentication XMLHttpRequests. |
| - * |
| - * @private |
| - * @param {number} xhrStatus Status (HTTP response code) of the XMLHttpRequest. |
| - * @return {remoting.Error} An error code to be raised. |
| - */ |
| -remoting.OAuth2Api.prototype.interpretXhrStatus_ = |
| - function(xhrStatus) { |
| - // Return AUTHENTICATION_FAILED by default, so that the user can try to |
| - // recover from an unexpected failure by signing in again. |
| - /** @type {remoting.Error} */ |
| - var error = remoting.Error.AUTHENTICATION_FAILED; |
| - if (xhrStatus == 400 || xhrStatus == 401 || xhrStatus == 403) { |
| - error = remoting.Error.AUTHENTICATION_FAILED; |
| - } else if (xhrStatus == 502 || xhrStatus == 503) { |
| - error = remoting.Error.SERVICE_UNAVAILABLE; |
| - } else if (xhrStatus == 0) { |
| - error = remoting.Error.NETWORK_FAILURE; |
| - } else { |
| - console.warn('Unexpected authentication response code: ' + xhrStatus); |
| - } |
| - return error; |
| -}; |
| - |
| /** |
| * Asynchronously retrieves a new access token from the server. |
| * |
| @@ -70,35 +30,6 @@ remoting.OAuth2Api.prototype.interpretXhrStatus_ = |
| */ |
| remoting.OAuth2Api.prototype.refreshAccessToken = function( |
| onDone, onError, clientId, clientSecret, refreshToken) { |
| - /** @param {XMLHttpRequest} xhr */ |
| - var onResponse = function(xhr) { |
| - if (xhr.status == 200) { |
| - try { |
| - // Don't use base.jsonParseSafe here unless you also include base.js, |
| - // otherwise this won't work from the OAuth trampoline. |
| - // TODO(jamiewalch): Fix this once we're no longer using the trampoline. |
| - var tokens = JSON.parse(xhr.responseText); |
| - onDone(tokens['access_token'], tokens['expires_in']); |
| - } catch (err) { |
| - console.error('Invalid "token" response from server:', |
| - /** @type {*} */ (err)); |
| - onError(remoting.Error.UNEXPECTED); |
| - } |
| - } else { |
| - console.error('Failed to refresh token. Status: ' + xhr.status + |
| - ' response: ' + xhr.responseText); |
| - onError(remoting.Error.fromHttpError(xhr.status)); |
| - } |
| - }; |
| - |
| - var parameters = { |
| - 'client_id': clientId, |
| - 'client_secret': clientSecret, |
| - 'refresh_token': refreshToken, |
| - 'grant_type': 'refresh_token' |
| - }; |
| - |
| - remoting.xhr.post(this.getOAuth2TokenEndpoint_(), onResponse, parameters); |
| }; |
| /** |
| @@ -117,41 +48,15 @@ remoting.OAuth2Api.prototype.refreshAccessToken = function( |
| */ |
| remoting.OAuth2Api.prototype.exchangeCodeForTokens = function( |
| onDone, onError, clientId, clientSecret, code, redirectUri) { |
| - /** @param {XMLHttpRequest} xhr */ |
| - var onResponse = function(xhr) { |
| - if (xhr.status == 200) { |
| - try { |
| - // Don't use base.jsonParseSafe here unless you also include base.js, |
| - // otherwise this won't work from the OAuth trampoline. |
| - // TODO(jamiewalch): Fix this once we're no longer using the trampoline. |
| - var tokens = JSON.parse(xhr.responseText); |
| - onDone(tokens['refresh_token'], |
| - tokens['access_token'], tokens['expires_in']); |
| - } catch (err) { |
| - console.error('Invalid "token" response from server:', |
| - /** @type {*} */ (err)); |
| - onError(remoting.Error.UNEXPECTED); |
| - } |
| - } else { |
| - console.error('Failed to exchange code for token. Status: ' + xhr.status + |
| - ' response: ' + xhr.responseText); |
| - onError(remoting.Error.fromHttpError(xhr.status)); |
| - } |
| - }; |
| - |
| - var parameters = { |
| - 'client_id': clientId, |
| - 'client_secret': clientSecret, |
| - 'redirect_uri': redirectUri, |
| - 'code': code, |
| - 'grant_type': 'authorization_code' |
| - }; |
| - remoting.xhr.post(this.getOAuth2TokenEndpoint_(), onResponse, parameters); |
| }; |
| /** |
| * Get the user's email address. |
| * |
| + * TODO(jamiewalch): Reorder these parameters to match the typical chrome API |
| + * convention of having callbacks at the end and remove the token parameter |
| + * to match remoting.HostListApi. |
|
Jamie
2015/01/08 18:57:18
I don't want to do this just yet because it will m
|
| + * |
| * @param {function(string):void} onDone Callback invoked when the email |
| * address is available. |
| * @param {function(remoting.Error):void} onError Callback invoked if an |
| @@ -160,26 +65,6 @@ remoting.OAuth2Api.prototype.exchangeCodeForTokens = function( |
| * @return {void} Nothing. |
| */ |
| remoting.OAuth2Api.prototype.getEmail = function(onDone, onError, token) { |
| - /** @param {XMLHttpRequest} xhr */ |
| - var onResponse = function(xhr) { |
| - if (xhr.status == 200) { |
| - try { |
| - var result = JSON.parse(xhr.responseText); |
| - onDone(result['email']); |
| - } catch (err) { |
| - console.error('Invalid "userinfo" response from server:', |
| - /** @type {*} */ (err)); |
| - onError(remoting.Error.UNEXPECTED); |
| - } |
| - } else { |
| - console.error('Failed to get email. Status: ' + xhr.status + |
| - ' response: ' + xhr.responseText); |
| - onError(remoting.Error.fromHttpError(xhr.status)); |
| - } |
| - }; |
| - var headers = { 'Authorization': 'OAuth ' + token }; |
| - remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), |
| - onResponse, '', headers); |
| }; |
| /** |
| @@ -193,27 +78,4 @@ remoting.OAuth2Api.prototype.getEmail = function(onDone, onError, token) { |
| * @return {void} Nothing. |
| */ |
| remoting.OAuth2Api.prototype.getUserInfo = function(onDone, onError, token) { |
| - /** @param {XMLHttpRequest} xhr */ |
| - var onResponse = function(xhr) { |
| - if (xhr.status == 200) { |
| - try { |
| - var result = JSON.parse(xhr.responseText); |
| - onDone(result['email'], result['name']); |
| - } catch (err) { |
| - console.error('Invalid "userinfo" response from server:', |
| - /** @type {*} */ (err)); |
| - onError(remoting.Error.UNEXPECTED); |
| - } |
| - } else { |
| - console.error('Failed to get user info. Status: ' + xhr.status + |
| - ' response: ' + xhr.responseText); |
| - onError(remoting.Error.fromHttpError(xhr.status)); |
| - } |
| - }; |
| - var headers = { 'Authorization': 'OAuth ' + token }; |
| - remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), |
| - onResponse, '', headers); |
| }; |
| - |
| -/** @type {remoting.OAuth2Api} */ |
| -remoting.oauth2Api = new remoting.OAuth2Api(); |