Reputation: 11
I'm trying to retrieve date of birth from google account after user sign in with google but i'm unable to get dateofbirth. I'm using Microsoft.AspNetCore.Authentication.Google Nuget Package to authenticate google user
Here is my code
// Startup file to authenticate user
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie()
.AddGoogle(options =>
{
options.ClientId = _configuration["GoogleLogin:ClientId"];
options.ClientSecret = _configuration["GoogleLogin:ClientSecret"];
options.AccessDeniedPath = "/login";
options.Scope.Add("https://www.googleapis.com/auth/plus.login");
options.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
options.Scope.Add("https://www.googleapis.com/auth/userinfo.profile");
options.Scope.Add("https://www.googleapis.com/auth/user.birthday.read");
});
// Here is my controller
var externalLoginInfo = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
this doesn't get any dob only name identifier, Display name, name, surname and email but birthday.
Upvotes: 1
Views: 134
Reputation: 387
You need to use People API to get the user's birthday. See https://developers.google.com/people/api/rest/v1/people/get. That also means you need to enable People API in your GCP Console. You would need an access token to all the People API to gain this information after user consents to it.
Similar to this Get gender for gmail when signup
Upvotes: 0