0

When I try to login to my sandbox using SalesforceSharp, I'm getting the following error message:

InvalidGrant: Authentication Failure

Here's what I've done:

  • Pass in the username, password, clientId, and clientSecret (SalesforceSharp)
  • Append my security token to the end of my password (SalesforceSharp)
  • Set "Relax IP Restrictions" on the connected app that I created for API access (Salesforce UI)
  • Set "All users may self-authorize" (Salesforce UI)
  • Set authFlow.TokenRequestEndpointUrl = "https://test.salesforce.com/services/oauth2/token"; instead of the default login.salesforce.com... (after the default failed) (SalesforceSharp)

Any ideas?

3
  • Did you check the login history for the user to see what it reports the error as? One of the parameters you passed in is not correct or you are using credentials for sandbox and using login or vice versa
    – Eric
    Aug 17, 2017 at 22:15
  • I haven't tried that particular library. Have you tried the Force.com Toolkit for .NET instead? Aug 17, 2017 at 22:17
  • When I did OAuth against a sandbox I needed a ConsumerKey and ConsumerSecret from a connected app that was created in a Sandbox. Might also be worth a try. I don't believe this is an actual requirement, but for some reason it was the only way I could get it to work. Aug 17, 2017 at 22:19

1 Answer 1

0

I am using SalesforceSharp regularly against my sandbox. I use the following to authenticate:

var authflow = new UsernamePasswordAuthenticationFlow(_clientIdParameter, _clientSecretParameter, _salesforceUser, _salesforcePass);
if (testMode) authflow.TokenRequestEndpointUrl = "https://test.salesforce.com/services/oauth2/token";

try
  {
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    _client.Authenticate(authflow);
  }
catch (Exception ex)
{
  //
}

Are you appending the instance to the username? (eg user@company.com.test101).

Only other thing I have done is whitelisted my IP to avoid the need to pass the security token.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.