0
votes

I want to use Google Login Credentials in my website.So i am using Google API. I get a google API token in URL. So i want to get Login User data? I am using C#. I got this URL after successfully Login and redirect back in My website:-

http://localhost:20885/WebServices/Welcome.aspx#state=/profile&access_token=ya29.AHES6ZRERYieYZIclNxQp3cPeXDnNWMP4IQuhDaj-TO_4wX2eqziRg&token_type=Bearer&expires_in=3600

Please Help me.

Thanks in advance.

2

2 Answers

0
votes

Take a look at this .Net library

http://www.dotnetopenauth.net/

This will do all the heavy OpenID/OAuth work for you. You just need to point it at Google's OpenID URL.

Requesting specific user data, such as email, is easy and explained here:

https://developers.google.com/accounts/docs/OpenID

0
votes

Use this javascript in your .aspx page:

// First, parse the query string
var params = {}, queryString = location.hash.substring(1),
regex = /([^&=]+)=([^&]*)/g, m;
while (m = regex.exec(queryString)) {
  params[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}

// And send the token over to the server
var req = new XMLHttpRequest();
// consider using POST so query isn't logged
req.open('GET', 'http://' + window.location.host + '/public/Google.aspx?' + queryString, true);

req.onreadystatechange = function (e) {
  if (req.readyState == 4) {
    if (req.status == 200) {
      window.location = params['state']
    }
    else if (req.status == 400) {
      alert('There was an error processing the token.')
    }
    else {
      alert('something else other than 200 was returned')
    }
  }
};
req.send(null);

Use it to call your the same or another .aspx page.