I added the following areas to access data from the user
#region Google var googleAuthenticationOptions = new GoogleOAuth2AuthenticationOptions() { ClientId = ConfigurationManager.AppSettings["Google_AppID"], ClientSecret = ConfigurationManager.AppSettings["Google_AppSecret"] }; googleAuthenticationOptions.Scope.Add("profile"); googleAuthenticationOptions.Scope.Add("email"); googleAuthenticationOptions.Provider = new GoogleOAuth2AuthenticationProvider() { OnAuthenticated = async context => { //context.Identity.AddClaim(new Claim("birthday", context.User.GetValue("birthday").ToString())); string claimType; bool bAddClaim = false; foreach (var claim in context.User) { claimType = string.Empty; bAddClaim = false; switch (claim.Key) { case "given_name": claimType = "FirstName"; bAddClaim = true; break; case "family_name": claimType = "LastName"; bAddClaim = true; break; case "gender": claimType = "gender"; bAddClaim = true; break; } if (bAddClaim) { string claimValue = claim.Value.ToString(); if (!context.Identity.HasClaim(claimType, claimValue)) context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, "XmlSchemaString", "Google")); } } } };
When debugging in context.user in a side foreach loop, setting a breakpoint I get the following information
{
"sub": "101111724115925537597",
"name": "Alok Nath",
"given_name": "Alok",
"family_name": "Nath",
"profile": "https://plus.google.com/101111724115925537597",
"picture": "https://lh3.googleusercontent.com/XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/
photo.jpg ",
"email": " aloknathbabuji786@gmail.com ",
"email_verified": true,
"gender": "male",
"locale": "en"
}
So, even after adding the "profile" area, I do not get the birthday as part of the return value. I made sure that the profile has the appearance of a birthday, open to the public, i.e. It is visible to everyone. Is there any specific area or specific settings that I need to make in order to receive a birthday from Google ?
Or is there a way to solve this problem, please post a solution
source share