Reputation: 25
I am using the token verifier google api
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=XYZ123
and it is giving me the user email id in the browser like
{
"iss": "https://accounts.google.com",
"sub": "110169484474386276334",
"azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
"aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
"iat": "1433978353",
"exp": "1433981953",
"email" OAuth scopes to the application.
"email": "[email protected]",
"email_verified": "true",
"name" : "Test User",
"picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
"given_name": "Test",
"family_name": "User",
"locale": "en"
}
Now I want to call this URL from my back end code and retrieve the mail id for doing authentication
I tried something like this
function(string access_token){
var url = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=" + access_token;
WebRequest request = WebRequest.Create(url);
request.Method = "GET";
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
XmlTextReader reader = new XmlTextReader(stream);
}
}
}
But not able to get the data from that json
Any alternatives?
I just need to get the email id of the user with access_token or idToken which the client will be sending to the server.
Upvotes: 0
Views: 89
Reputation: 25
Solved
var json = new WebClient().DownloadString(url);
used WebClient for getting data from browser
after deserializing I got the data.
Upvotes: 0