Error with SalesForce authentication from C# Client(s)

后端 未结 1 519
别跟我提以往
别跟我提以往 2020-12-19 09:13

I am new to SalesForce and am working through getting up to speed with the basics as we will be beginning a large integration project next week. For at least part of our in

相关标签:
1条回答
  • 2020-12-19 09:38

    If you haven't solved this yet, I think this might be your issue. So according to this: https://help.salesforce.com/apex/HTViewSolution?id=000221207 Starting from June 2016 Salesforce will is disabling TLS 1.0 encryption accross its whole platform in a phased approach.

    If you are on any version prior to .net 4.6, it means that you won't have TLS 1.1/1,2 switched on by default. There is a little list here of options you can use to enable it: https://help.salesforce.com/apex/HTViewSolution?id=000221207#Inboundintegrations

    For a console application like yours, just tested on my side and the following worked for me (on .net 4.5.2):

            string LoginUrl = "https://login.salesforce.com/services/oauth2/token";
            //the line below enables TLS1.1 and TLS1.2
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            FormUrlEncodedContent content = new FormUrlEncodedContent(new[]
            {
            new KeyValuePair<string, string>("grant_type", "password"),
            new KeyValuePair<string, string>("client_id","CLIENTID"),
            new KeyValuePair<string, string>("client_secret","CLIENTSECRET"),
            new KeyValuePair<string, string>("password","PASSWORD + SECURITYTOKEN"),
            new KeyValuePair<string, string>("username", "USERNAME")
            });
            HttpResponseMessage response;
            using (HttpClient client = new HttpClient())
            {
                response = client.PostAsync(LoginUrl, content).Result;
            }
            Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            Console.WriteLine(response.StatusCode);
            Console.ReadLine();
    
    0 讨论(0)
提交回复
热议问题