Commit 7e38f0ec authored by rmsousa@chromium.org's avatar rmsousa@chromium.org

Change userinfo endpoint to the JSON one.

NOTRY=true


Review URL: https://chromiumcodereview.appspot.com/11818011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175895 0039d316-1c4b-4281-b951-d872f2087c98
parent 35072c28
...@@ -514,11 +514,17 @@ remoting.OAuth2.prototype.getEmail = function(onOk, onError) { ...@@ -514,11 +514,17 @@ remoting.OAuth2.prototype.getEmail = function(onOk, onError) {
var onResponse = function(xhr) { var onResponse = function(xhr) {
var email = null; var email = null;
if (xhr.status == 200) { if (xhr.status == 200) {
// TODO(ajwong): See if we can't find a JSON endpoint. var result = jsonParseSafe(xhr.responseText);
email = xhr.responseText.split('&')[0].split('=')[1]; if (result && 'email' in result) {
window.localStorage.setItem(that.KEY_EMAIL_, email); window.localStorage.setItem(that.KEY_EMAIL_, result['email']);
onOk(email); onOk(result['email']);
return; 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); console.error('Unable to get email address:', xhr.status, xhr);
if (xhr.status == 401) { if (xhr.status == 401) {
...@@ -531,8 +537,7 @@ remoting.OAuth2.prototype.getEmail = function(onOk, onError) { ...@@ -531,8 +537,7 @@ remoting.OAuth2.prototype.getEmail = function(onOk, onError) {
/** @param {string} token The access token. */ /** @param {string} token The access token. */
var getEmailFromToken = function(token) { var getEmailFromToken = function(token) {
var headers = { 'Authorization': 'OAuth ' + token }; var headers = { 'Authorization': 'OAuth ' + token };
// TODO(ajwong): Update to new v2 API. remoting.xhr.get('https://www.googleapis.com/oauth2/v1/userinfo',
remoting.xhr.get('https://www.googleapis.com/userinfo/email',
onResponse, '', headers); onResponse, '', headers);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment