function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dev_AryaDev_Arya 

Dotnet integration using Connected App ends in login over insecure channel

Hi All,

I am trying to develop a sample dotnet integration app using the instructions specified in this tutorial:
https://www.youtube.com/watch?v=c0R7_4ctgHU

I have setup  the connected app and in the connected app, the callback url is
"https://loginsalesforce.com/services/oauth2/callback" . My Org has a custom domain, does that make any difference in setting up the connected app? I also checked the TLS settings, tried activating and deactivating the TLS 1.2, but nothing works. My login function is as following:
private async void btn_login_Click(object sender, EventArgs e)
        {
            String sfdcUserName = txt_username.Text;
            String sfdcPassword = txt_password.Text;
            String sfdcSecurityToken = txt_securitytoken.Text;

            String SfdcloginPassword = sfdcPassword + sfdcSecurityToken;

            txt_output.Text = "";
            var dictionaryForUrl = new Dictionary<String, String>
            {
                {"grant_type","password" },
                {"client_id", sfdcConsumerkey},
                {"client_secret", sfdcConsumerSecret},
                {"username", sfdcUserName},
                {"password", SfdcloginPassword}
            };

            HttpClient authhc = new HttpClient();
            HttpContent httpContent = new FormUrlEncodedContent(dictionaryForUrl);
            HttpResponseMessage httpresponse = await authhc.PostAsync("https://login.salesforce.com/services/oauth2/token", httpContent);
            String message = await httpresponse.Content.ReadAsStringAsync();
            //Console.WriteLine(message); 

            JObject jsonObj = JObject.Parse(message);
            authToken = (String)jsonObj["access_token"];
            ServiceURL = (String)jsonObj["instance_url"];
            String ErrorType = "";
            String ErrorMsg = "";
            ErrorType = (String)jsonObj["error"];
            ErrorMsg = (String)jsonObj["error_description"];
            // Console.WriteLine("AuthURL: " + authToken);
            //Console.WriteLine("ServiceURL: " + ServiceURL);

            if ((authToken != null && authToken != "") && ErrorMsg == null)
            {
                txt_output.AppendText("Login Successfull!!\n");
                txt_output.AppendText("Instance url: " + ServiceURL);
            }
            else if (authToken == null && (ErrorMsg != "" && ErrorMsg != null))
            {
                txt_output.AppendText("Login unsuccessfull!!\n");
                txt_output.AppendText("Error Type: " + ErrorType + "\n");
                txt_output.AppendText("Error: " + ErrorMsg);
            }

        }

For using this REST service to connect the salesforce, do I need additional code? 

Thanks.

Best regards,
Dev
Best Answer chosen by Dev_Arya
Dev_AryaDev_Arya
Never mind, I found the answer:
Write this code before initiating the authenticationClient:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
Happy coding :-)
Cheers, Dev