'Logging issue - Sales force C#

Here is the code snippet Error: {"error":"invalid_client_id","error_description":"client identifier invalid"} connecting passing correct clientid, clientsecret, username, password passing securityToken empty

Any luck can we connect without securityToken

    public void Login()
    {
        String jsonResponse;
        try
        {
            using (var client = new HttpClient())
            {
                var request = new FormUrlEncodedContent(new Dictionary<string, string>
                {
                    { "grant_type","password"},
                    { "client_id", ClientId},
                    { "client_secret", ClientSecret},
                    { "username", Username},
                    { "password", Password + Token}

                });
                request.Headers.Add("X-PreetyPrint", "1");
                var response = client.PostAsync(LOGIN_ENDPOINT, 
                                 request).Result;//client.SendAsync(request);//
                jsonResponse = response.Content.ReadAsStringAsync().Result;// 
                                 Content.ReadAsStringAsync();
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }


        var values = JsonConvert.DeserializeObject<Dictionary<string, string>> 
                     (jsonResponse);
        AuthToken = values["access_token"];
        InstanceUrl = values["instance_url"];
        Console.WriteLine("Auth Token = " + AuthToken);
        Console.WriteLine("Instance Url = " + InstanceUrl);

    }


Solution 1:[1]

To login without security token you need to be on trusted network. For example if your office / VPN / application server has static IP - your Salesforce admin can add it to Setup -> Network Access. More info: https://help.salesforce.com/s/articleView?id=000333031&type=1

If the IP is not static and this has to be done completely server-side (withotu human logging in in the browser and authorising your app)... you could try to login without password. Read up about JWT and (shameless plug): https://stackoverflow.com/a/72119994/313628, https://stackoverflow.com/a/63897503/313628

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eyescream