Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help validating token - I cannot read JSON response data
    text
    copied!<p>I am having problem reading the JSON response data after sending Google OAuth2 token validation request per the <a href="https://developers.google.com/accounts/docs/OAuth2UserAgent#validatetoken" rel="nofollow noreferrer">documentation</a>.</p> <p><strong>Here is the Google OAuth2 token validation request:</strong></p> <pre><code>$http.get('https://www.googleapis.com/oauth2/v1/tokeninfo', {params: {access_token: accessToken.token}}) .success(function (data, status, headers, config) { $log.info("sendValidationRequest() method: data: " + data); deferred.resolve(data); accessToken.state = getSession().state = $window.sessionStorage.state = "AccessTokenValidated"; }) .error(function (data, status, headers, config) { //handle error }); </code></pre> <p>So when I inspect that JSON response data object I get the following:</p> <pre><code>data.audience; // undefined data.scope; // undefined data.userid; // undefined data.expires_in; //undefined </code></pre> <p>This is what the JSON Response data looks like inside Chrome Developer Tools: <img src="https://i.stack.imgur.com/QK00O.png" alt="enter image description here"></p> <p>I was expecting the JSON response data to be a JSON Array per the <a href="https://developers.google.com/accounts/docs/OAuth2UserAgent#validatetoken" rel="nofollow noreferrer">documentation</a>. The JSON response data seems to be encoded. How do I resolve this?</p> <p><strong>Here is my HTTP Header Request:</strong></p> <pre><code>GET https://www.googleapis.com/oauth2/v1/tokeninfo? access_token=ya29.AHES6ZQBj6feCrXuDoqwA3FpX1T1HO8fH1eWegJbiBTp7Cs HTTP/1.1 :host: www.googleapis.com origin: http://localhost:8080 accept-encoding: gzip,deflate,sdch accept-language: en-US,en;q=0.8 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 :path: /oauth2/v1/tokeninfo? access_token=ya29.AHES6ZQBj6feCrXuDoqwA3FpX1T1HO8fH1eWegJbiBTp7Cs accept: application/json, text/plain, */* :version: HTTP/1.1 referer: http://localhost:8080/calendar-app/ :scheme: https :method: GET </code></pre> <p><strong>Here is my HTTP Response Header:</strong></p> <pre><code>HTTP/1.1 200 OK status: 200 OK version: HTTP/1.1 access-control-allow-origin: http://localhost:8080 access-control-expose-headers: Cache-Control,Content-Encoding,Content-Length,Content-Type,Date,Expires,Pragma,Server cache-control: no-cache, no-store, max-age=0, must-revalidate content-encoding: gzip content-length: 182 content-type: application/json; charset=UTF-8 date: Sat, 17 Aug 2013 08:00:05 GMT expires: Fri, 01 Jan 1990 00:00:00 GMT pragma: no-cache server: GSE x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block </code></pre> <p>Any help with resolving my issue is much appreciated.</p> <p>Thank you.</p> <p>After doing some research, I found that this a problem specific to AngularJS $http services; as this is not a problem with JQuery. Here is what my validate access token code looks like in JQuery:</p> <pre><code>function validateToken() { $.ajax({ url: 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + accessToken, data: null, success: function(response){ console.log('Our token is valid. and response.audience value is defined.'); }, error: function(error) { console.log('Our token is not valid....'); }, dataType: "jsonp" }); } </code></pre> <p><strong>The JQuery Ajax request headers are different request headers are different from $http service request header (See above):</strong></p> <pre><code>GET https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=ya29.AHES6ZTewZF3-aEJ3p8mdJahvTtZDNELYjpqLsGaB10Fnmk&amp;callback=jQuery172036758901784196496_1376731301308&amp;_=1376731301856 HTTP/1.1 :host: www.googleapis.com accept-encoding: gzip,deflate,sdch accept-language: en-US,en;q=0.8 user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36 :path: /oauth2/v1/tokeninfo?access_token=ya29.AHES6ZTewZF3-aEJ3p8mdJahvTtZDNELYjpqLsGaB10Fnmk&amp;callback=jQuery172036758901784196496_1376731301308&amp;_=1376731301856 accept: */* :version: HTTP/1.1 referer: http://localhost:8080/calendar-app/google-oauth-test2.html :scheme: https :method: GET </code></pre> <p><strong>Which in turns the Google Response headers are different when the request was issued by $http service (See Above):</strong></p> <pre><code>HTTP/1.1 200 OK status: 200 OK version: HTTP/1.1 cache-control: no-cache, no-store, max-age=0, must-revalidate content-encoding: gzip content-length: 235 content-type: text/javascript; charset=UTF-8 date: Sat, 17 Aug 2013 09:21:40 GMT expires: Fri, 01 Jan 1990 00:00:00 GMT pragma: no-cache server: GSE x-content-type-options: nosniff x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block </code></pre> <p>So now the question becomes, how to get AngularJS $http service request headers to match what JQuery's AJAX request headers look like? Or is there another way to get the same result; which is to get the proper JSON array object back from google after a successful access token validation?</p> <p>Again, any help with this is much appreciated!</p> <p>I am updating post because there seems to be some questions of whether or not I have a space in the URL and that I am not show the raw JSON response. I hope this picture from chrome Developer's Tools clears this up.</p> <p><img src="https://i.stack.imgur.com/Znart.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/mSPs5.png" alt="enter image description here"></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload