You need to sign in to do that
Don't have an account?
Todd Peterson
oauth2 error bad request
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.
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.
However, Salesforce has disabled TLS 1.1 . We now need to use TLS1.2 or higher for creating a new connection
- https://help.salesforce.com/articleView?id=000321556&type=1&mode=1 (https://help.salesforce.com/articleView?id=000321556&type=1&mode=1)
Try changing following code just to make sure that connection is being made using TLS1.2 To below This again depends on the .Net version you are using.I'm leaning towards something not set up in the Connected App correctly or possibly a permission in Salesforce??
I've added "Full access" along with "Access and manage your data" as part of my Selected OAuth Scopes.
I've changed the Permitted Users to "All Users may self-authorize".
Set IP Relaxation to "Relax IP restrictions". My Timeout Value is "None".
{
"error" : "invalid_grant",
"error_description" : "authentication failure"
}
That means either the username or password or both are incorrect? Isn't that the username and password that I use to sign into Salesforce.com ?
Try sending only the password instead of password+token in the auth request. Salesforce expect token only from untrusted network. If even this does not work then this could be issue with Connected App auth policies setup. Please refer these pages for more details