function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Yuriy TsemashkoYuriy Tsemashko 

REST API, "authentication failure" with user&password authentication

Hello.
I'm trying to integrate Salesforce into my application and i decided to use REST API and user&password authorization. I registered developer account, connected an application with enabled OAuth settings.
It's my settings:

Unfortunelly, i receive "{"error_description":"authentication failure","error":"invalid_grant"}" each time when i do authorization. It's example of my calling:
curl https://test.salesforce.com//services/oauth2/token -d "grant_type=password&client_id=CONSUMERKEY&client_secret=CONSUMERSECRET&username=yuriy%40example.com&password=passwordTOKEN"

Here are my selected scopes:
Access your basic information (id, profile, email, address, phone)
Access and manage your data (api)
Provide access to your data via the Web (web)
Full access (full)
Access and manage your Chatter data (chatter_api)
Provide access to custom applications (visualforce)
Perform requests on your behalf at any time (refresh_token, offline_access)
Allow access to your unique identifier (openid)
Access custom permissions (custom_permissions

Callback URL is just "https://login.salesforce.com/services/oauth2/authorize"

Could you please help me to understand what i'm doing wrong? I ebabled all policies, my user(who i'm trying to log in) is superadmin of this account. Thank you!
 
Best Answer chosen by Yuriy Tsemashko
Gaurav KheterpalGaurav Kheterpal
Your callback URL is set to login.salesforce.com while the endpoint that you are hitting is test.salesforce.com

They should refer to the same instance.

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker

All Answers

Gaurav KheterpalGaurav Kheterpal
Your callback URL is set to login.salesforce.com while the endpoint that you are hitting is test.salesforce.com

They should refer to the same instance.

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others and improve the overall quality of Discussion Forums.

Gaurav Kheterpal
Certified Force.com Developer| Salesforce Mobile Evangelist| Developer Forums Moderator| Dreamforce Speaker
This was selected as the best answer
Himanshu ParasharHimanshu Parashar
Hi Yuriy,

As you said you are using developer account you need to add security token in your password. after that it should work.

Here is a sample code from PHP
 
define("USERNAME", "test@example.com");
define("PASSWORD", "testexamplle");
define("SECURITY_TOKEN", "kljkljfsakjbGKJKLJLKDF");
define("TOKEN_URL", "https://login.salesforce.com/services/oauth2/token");

$params = "grant_type=password&client_id=" . CLIENT_ID
			. "&client_secret=" . CLIENT_SECRET . "&username=" . USERNAME
			. "&password=" . PASSWORD.SECURITY_TOKEN;
			$ch = curl_init(TOKEN_URL);
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_POST, true);
			curl_setopt($ch, CURLOPT_HEADER, false);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
			curl_setopt($ch, CURLOPT_POSTFIELDS, $params);

			$json_response = curl_exec($ch);



Thanks,
Himanshu
Salesforce Certified Developer | Administrator | Service Cloud Consultant

P.S.  If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Yuriy TsemashkoYuriy Tsemashko
Thank you Gaurav.
But uhmm... it works but i don't understand: callback URL is just url which will be used in Oauth2 authroization. It might be, i dunno, my-super-software.com/callback or localhost:3000/salesforce/callback. Ok, anyway it works now. It will be better if i don't try to understand this enterprise software.