• Todd Peterson
  • NEWBIE
  • 0 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
I'm using .Net to try and create a simple client app to connect to Salesforce for a demo application.   Steps I've completed:

1) In App Manager, created my Connect App.   Have Enable for Device Flow checked.  Generated my Initial Access Token, my Consumer Key, and my Consumer Secret.

2) Here's my .Net code:

            HttpClient authClient = new HttpClient();

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11;

            Dictionary<string, string> contDictionary = new Dictionary<string, string>();
            contDictionary.Add("grant_type", "password");
            contDictionary.Add("client_id", consumerKey);
            contDictionary.Add("client_secret", consumerSecret);
            contDictionary.Add("username", userName);
            contDictionary.Add("password", pwd + token);


            HttpContent content = new FormUrlEncodedContent(contDictionary);
            HttpResponseMessage message = await authClient.PostAsync("https://login.salesforce.com/services/oauth2/token", content);

            string responseString = await message.Content.ReadAsStringAsync();

            var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseString);
            string authToken = values["access_token"];
            string instanceUrl = values["instance_url"];

When the PostAsync is called, I get a "Bad Request". 

Any help would be greatly appreciated.
I'm using .Net to try and create a simple client app to connect to Salesforce for a demo application.   Steps I've completed:

1) In App Manager, created my Connect App.   Have Enable for Device Flow checked.  Generated my Initial Access Token, my Consumer Key, and my Consumer Secret.

2) Here's my .Net code:

            HttpClient authClient = new HttpClient();

            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11;

            Dictionary<string, string> contDictionary = new Dictionary<string, string>();
            contDictionary.Add("grant_type", "password");
            contDictionary.Add("client_id", consumerKey);
            contDictionary.Add("client_secret", consumerSecret);
            contDictionary.Add("username", userName);
            contDictionary.Add("password", pwd + token);


            HttpContent content = new FormUrlEncodedContent(contDictionary);
            HttpResponseMessage message = await authClient.PostAsync("https://login.salesforce.com/services/oauth2/token", content);

            string responseString = await message.Content.ReadAsStringAsync();

            var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(responseString);
            string authToken = values["access_token"];
            string instanceUrl = values["instance_url"];

When the PostAsync is called, I get a "Bad Request". 

Any help would be greatly appreciated.