0
votes

I have created google api services app and verify that user.profile info scope is by default added.

Authentication, token and get the user info is working fine for me, however few fields are missing in get user info api response.

I am using below mentioned endpoints to communicate with google api.


WebRequest request = WebRequest.Create(googleGetUrl + $"&access_token={accesstoken}");
request.Credentials = CredentialCache.DefaultCredentials;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream receiveStream = response.GetResponseStream())
    {
        using (StreamReader readStream = new StreamReader(receiveStream))
        {
            string responseFromServer = readStream.ReadToEnd();

            return JsonConvert.DeserializeObject<GoogleUser>(responseFromServer);
        }
    }
}

I am getting the json response as mentioned below

{
  id: "xxxxxxxxxxxxx",
  email: "[email protected]",
  verified_email: true,
  picture: "https://validurl/photo.jpg",
  hd: "getting value"
}

But what I want expect like below mentioned Json

{
  id: "xxxxxxxxxxxxx",
  email: "[email protected]",
  verified_email: true,
  picture: "https://validurl/photo.jpg",
  hd: "getting value",
  name: "some value",
  family_name: "some value",
  given_name: "some value"
}

scope configuration :

enter image description here

Please let me know if I have missed any configuration. Your help would be much appreciated.

Kind Regards, Mohsin

2
I'm guessing the endpoint versions you chose simply don't support those name fields. I would contact Google Support, or look at this similar article: stackoverflow.com/questions/7130648/…. It lists other sources you could use.Max Voisard
I have tried googleapis.com/oauth2/v1/… this one as well. same result no luck.Mohsinkhan Pathan
@MohsinkhanPathan, This may help you => stackoverflow.com/a/22459811/5514820er-sho
I have added scope configuration snap.Mohsinkhan Pathan

2 Answers

1
votes

I was missing scope parameter in authentication URL and having used below URL works for me.

return string.Format( "https://accounts.google.com/o/oauth2/auth?client_id={0}&redirect_uri={1}&response_type=code&scope={2}", ClientId, CallBackUrl, "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email");

Kind Regards, Mohsin Pathan

0
votes

The response from the userinfo endpoint is not standards all oauth servers have their own implementation of what they will return. If you want to get more information you should try the people api. No one should return email unless you request the email scope. And google stopped returning verified_email a few years ago i think.

GET /v1/people/me HTTP/1.1
Host: people.googleapis.com
Content-length: 0
Authorization: Bearer aJxKQvzgCj5fa86EbB_AYqjt-