+ Start a Discussion
Sneha KavinkarSneha Kavinkar 

Authentication failure - API access through .NET

Hello,

I am trying to access API through .NET by following the steps mentioned in following link https://github.com/developerforce/Force.com-Toolkit-for-NET/blob/master/samples/SimpleConsole/Program.cs . For some reason i get error stating "One or more errors occurred,authentication failure"
I have double checked my credentials to ensure they are proper.
Can anyone tell me what can be possible reson for this error or if there's any other way to access API using .NET
Tammer SalemTammer Salem
Are you sure you're not using delegated authentication (a single sign-on provider)? Usually this is just an issue of the username not being correct, or targeting the wrong url (or the security token being out of date - try resetting it, and passing it throgh again). Is it possible to put the full stack trace here?
Sneha KavinkarSneha Kavinkar
Thanks Tammer!
Below is the stack trace
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at SalesForce.Program.Main(String[] args) in d:\Study Material\SalesForce\SalesForce\SalesForce\Program.cs:line 35

I have tried resetting the security token,still it didn't work.
Also could you please guide on how to check whether account is "single sign-on provider" enabled.
Tammer SalemTammer Salem
Can't see anything extra in the stack trace.

You can check if you are using delegated authentication by going to security controls -> Single Sign on Settings (it is either empty or will define some SAML provider). I suspect though that if you're using a username/password in the code then you have already logged in using that user through the website?
Sneha KavinkarSneha Kavinkar
There are no settings defined in "Single Sign-On settings" section.
I have logged out from all the sessions on website.
Tammer SalemTammer Salem
Have you checked if the user is API enabled in their profile or permission set (https://ebsta.zendesk.com/entries/53460205-How-do-I-enable-API-access-in-Salesforce-)?
 
Tammer SalemTammer Salem
Also have you followed the approach to create a consumer key (http://help.salesforce.com/apex/HTViewHelpDoc?id=remoteaccess_oauth_web_server_flow.htm&language=en_US)? Are you using the Connect Apps settings?
Sneha KavinkarSneha Kavinkar
Hi Tammer

My account has been created by thirs person and has assigned me System administrator privileges.Under permission set I can see two options.One of them is Edit enable and API enabled option is selected for it.However the other one doesn't give me edit option and the API Enabled section is also not checked for it. Do you think that will make any difference?
Tammer SalemTammer Salem
Ok so under a profile or permission set, there are a section called system permissions. There should only be one option called API Enabled and it should be selected if you want your code to work (hopefully the name API enabled is self-explanatory). Your user only belongs to one profile, but might be associated to multiple permission sets. Whichever is assigned to you, at a minimum you must have the API enabled (at least one profile or permission set that your user is assigned to). It sounds from what you are saying that one of the permissions sets has API enabled option - and if you're sure that it is assigned to your user then that's correct (you can check if your user is assigned by clicking the "Manage Assignments" in the permission set and you should see your user assigned).
algot algotalgot algot
I had the same error with all keys set correct and spent a lot of time trying to figure out why I cannot connect.
Finally I've found that in Setup -> Manage Connected Apps -> Click "MyAppName" -> Click "Edit Policies".
In the 'Permitted Users' field value "All users may self-authorize" should be set.
Sajal PalSajal Pal
@algot algot, This trick worked for me Thanks