public static GoogleUser ValidateToken(string idToken) { var jwtHandler = new JwtSecurityTokenHandler(); var claims = jwtHandler.ValidateToken(idToken, TokenValidationParameters, out var validatedToken); if (validatedToken != null) { return(GoogleUser.FromClaims(claims.Claims)); } throw new Exception("Could not validate google identity."); }
internal static GoogleUser FromClaims(IEnumerable <Claim> claims) { var user = new GoogleUser(); foreach (var claim in claims) { switch (claim.Type) { case ClaimsConstants.NameIdentifier: user.NameIdentifier = claim.Value; break; case ClaimsConstants.EmailAddress: user.EmailAddress = claim.Value; break; case ClaimsConstants.GivenName: user.GivenName = claim.Value; break; case ClaimsConstants.Surname: user.Surname = claim.Value; break; case ClaimsConstants.GoogleClaims.EmailVerified: user.EmailVerified = Convert.ToBoolean(claim.Value); break; case ClaimsConstants.GoogleClaims.PictureUrl: user.PictureUrl = claim.Value; break; case ClaimsConstants.GoogleClaims.Locale: user.Locale = claim.Value; break; } } return(user); }