Chromium Code Reviews| Index: remoting/webapp/oauth2.js |
| diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js |
| index 9956f5a026edb30fca3157283517fe91aa7515f2..343063c0b39b71c883f2ca5baa0d0db1a797cc53 100644 |
| --- a/remoting/webapp/oauth2.js |
| +++ b/remoting/webapp/oauth2.js |
| @@ -492,11 +492,16 @@ remoting.OAuth2.prototype.getEmail = function(onOk, onError) { |
| var onResponse = function(xhr) { |
| var email = null; |
| if (xhr.status == 200) { |
| - // TODO(ajwong): See if we can't find a JSON endpoint. |
| - email = xhr.responseText.split('&')[0].split('=')[1]; |
| - window.localStorage.setItem(that.KEY_EMAIL_, email); |
| - onOk(email); |
| - return; |
| + var result = jsonParseSafe(xhr.responseText); |
| + if (result && 'email' in result) { |
| + window.localStorage.setItem(that.KEY_EMAIL_, result['email']); |
| + onOk(result['email']); |
| + return; |
| + } else { |
| + console.error('Cannot parse userinfo response: ', xhr.responseText); |
|
Jamie
2013/01/09 20:47:13
For xhr errors, I usually try to log both the resp
|
| + onError(remoting.Error.UNEXPECTED); |
| + return; |
| + } |
| } |
| console.error('Unable to get email address:', xhr.status, xhr); |
| if (xhr.status == 401) { |
| @@ -509,8 +514,7 @@ remoting.OAuth2.prototype.getEmail = function(onOk, onError) { |
| /** @param {string} token The access token. */ |
| var getEmailFromToken = function(token) { |
| var headers = { 'Authorization': 'OAuth ' + token }; |
| - // TODO(ajwong): Update to new v2 API. |
| - remoting.xhr.get('https://www.googleapis.com/userinfo/email', |
| + remoting.xhr.get('https://www.googleapis.com/oauth2/v1/userinfo', |
| onResponse, '', headers); |
| }; |