public async Task <string> Invoke(SignUpWithGoogleParams param) { try { if (await tokenRepository.ValidateGoogleIdToken(param.Token)) { var googleIdTokenSample = new { sub = "", email = "", email_verified = false, picture = "", locale = "" }; var handler = new JwtSecurityTokenHandler(); var tkn = handler.ReadJwtToken(param.Token); var idToken = JsonConvert.DeserializeAnonymousType(tkn.Payload.SerializeToJson(), googleIdTokenSample); string name = idToken.email.Substring(0, idToken.email.IndexOf('@')); var googleusr = await userRepository.getUserIfGoogleAuth(idToken.sub); if (googleusr != null) { return(await RefreshSessionAsync(googleusr, param.SessionId)); } else if (idToken.email_verified) { var avatarId = Guid.NewGuid(); await SaveAvatar(idToken.picture, avatarId); var userId = Guid.NewGuid(); var possibleUser = new User { User_Id = userId, UserName = name, Email = idToken.email, Password = authOptions.GeneratePaswordWithSaltForUser(userId), Locale = idToken.locale, GoogleId = idToken.sub, Role_Name = "User", Avatar = avatarId }; return(await RegisterUser(possibleUser)); } else { throw new NonConfirmedEmailException(); } } else { throw new NonValidatedGoogleIdTokenException(); } } catch { throw; } }