0

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: "dummy@email.com",
  verified_email: true,
  picture: "https://validurl/photo.jpg",
  hd: "getting value"
}

But what I want expect like below mentioned Json

{
  id: "xxxxxxxxxxxxx",
  email: "dummy@email.com",
  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

  • Try this api => [https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=youraccess_token](https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=youraccess_token) – er-sho Apr 10 '19 at 06:20
  • 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: https://stackoverflow.com/questions/7130648/get-user-info-via-google-api. It lists other sources you could use. – Max Voisard Apr 10 '19 at 06:20
  • I have tried https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=youraccess_token this one as well. same result no luck. – Mohsinkhan Pathan Apr 10 '19 at 06:24
  • @MohsinkhanPathan, This may help you => https://stackoverflow.com/a/22459811/5514820 – er-sho Apr 10 '19 at 06:27
  • I have added scope configuration snap. – Mohsinkhan Pathan Apr 10 '19 at 06:31

2 Answers2

1

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"); 
WhatsThePoint
  • 3,395
  • 8
  • 31
  • 53
0

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-
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449