| Index: remoting/webapp/oauth2.js
|
| diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js
|
| index 9956f5a026edb30fca3157283517fe91aa7515f2..da51a4ccdc0b62954ccfbfab7eb1947e79c4f703 100644
|
| --- a/remoting/webapp/oauth2.js
|
| +++ b/remoting/webapp/oauth2.js
|
| @@ -492,11 +492,17 @@ 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, xhr);
|
| + onError(remoting.Error.UNEXPECTED);
|
| + return;
|
| + }
|
| }
|
| console.error('Unable to get email address:', xhr.status, xhr);
|
| if (xhr.status == 401) {
|
| @@ -509,8 +515,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);
|
| };
|
|
|
|
|