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

Unified Diff: remoting/webapp/oauth2.js

Issue 11818011: Change userinfo endpoint to the JSON one. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Log the xhr object Created 7 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
};
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698