2

I'm having a terrible time...I am trying to get coldfusion to get a token from salesforce, but I am stuck on the following error

{"error":"invalid_grant","error_description":"authentication failure"}

ive tried cfscript

local.http = new Http(url='https://test.salesforce.com/services/oauth2/token',method='post');

      local.http.addParam(type='header',name='content-type',   value='application/x-www-form-urlencoded');
      local.http.addParam(type='formField',name='grant_type',   value='password');
      local.http.addParam(type='formField',name='client_id',    value='client_id');
      local.http.addParam(type='formField',name='client_secret',  value='client_password_string');
      local.http.addParam(type='formField',name='username',   value='user@email.com');
      local.http.addParam(type='formField',name='password',   value='userspassword');
      local.http.addParam(type='formField',name='format',     value='json');

      local.httpSendResult = local.http.send();
      rc.httpResult = httpSendResult.getPrefix();

ive tried cfhttp tags

<cfhttp url="https://test.salesforce.com/services/oauth2/token" method="POST">
         <cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" />
         <cfhttpparam type="formField" name="grant_type" value="password" />

         <cfhttpparam type="formField" name="client_id" value="client_id" />
         <cfhttpparam type="formField" name="client_secret" value="client_password_string" />
         <cfhttpparam type="formField" name="username" value="user@email.com" />
         <cfhttpparam type="formField" name="password" value="userspassword" />

        </cfhttp>       
        <cfset rc.result = cfhttp.fileContent />     

however the same exact call executed by cUrl on my local machine works perfectly fine

    curl -d "grant_type=password" 
   -d "client_id=client_id" 
   -d "client_secret=client_secret_string" 
   -d "username=user@email.com.dev" 
   -d "password=userpassword" https://test.salesforce.com/services/oauth2/token

ive made sure that my ip range is whitelisted, my ip relaxation is set to relax, allusers may self authorize, ive tried different username and password parameters, all i get is the same error about invalid grants

any help is very appreciated

6
  • in ur cfScript & cfHttp tags, you were using username as 'user@email.com' where as in cUrl, you were using username=user@email.com.dev? or these are dummy values. Just want to make sure you were not using diff usernames. – night crawler Sep 12 '17 at 21:16
  • Have you seen SalesforceApiWrapper.cfc? – Daniel Ballinger Sep 12 '17 at 23:05
  • @DanielBallinger i have, but couldnt get past the jsonparser required part...although it is good code base to help start me – Jay Rizzi Sep 18 '17 at 14:03
  • 1
    @DanielBallinger yes it was saying in the log "insecure connection" , so i ended up tracking it down as the coldfusion server was using TLS 1.0 which was deprecated in spring 17 ...that one wasnt fun to track down – Jay Rizzi Sep 19 '17 at 14:19
  • 1
    @JayRizzi Can you post that as an answer. Try to include any terms that those searching for the same problem would be looking. At least you might save someone in the future from going through the same process. – Daniel Ballinger Sep 19 '17 at 19:53

Your Answer

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

Browse other questions tagged or ask your own question.