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
suraj pawar 2suraj pawar 2 

API Integration & SSO

i have created an app in salesforce and provided callback url, i received the code successfully but when i am requesting for token using callback url, client id and client secret key, i am getting an error i.e Invalid grant, authorization code invalid.
Ashish_SFDCAshish_SFDC
Hi Suraj, 


Invalid_grant: the provided authorization code is not valid, has been revoked or has expired (after 5 minutes). Note that both successful and unsuccessful requests revoke the code. Also check that the redirect_uri parameter is included if necessary.

https://dev.moves-app.com/docs/authentication#accesstoken


See the similar thread, 

This is a sample of how to get the access_token:

Request

Realize an HTTP POST to https://[login].salesforce.com/services/oauth2/token **you must select between test or login according the environment we want to use (sandbox or production).

Body:

client_id=CLIENT-ID
&client_secret=CLIENTE-SECRET
&password=PASSWORD+SECURITY-TOKEN
&username=USERNAME
&grant_type=password
** replace default values with values from your org/user
Headers:

content-tpe: application/x-www-form-urlencoded

http://salesforce.stackexchange.com/questions/25241/server-side-rest-authentication


Also see the link below, 

https://github.com/kevinohara80/nforce/issues/30


Regards,
Ashish


suraj pawar 2suraj pawar 2
Thanks ashish for your help..!!


i have used grant_type = pasword  and  i am getting the correct reponse i:e access token,  but when i am using grand_type= authorization_code it is giving me an error "Invalid grant, authorization code invalid"  , so can you please help me to rectify this problem


grant_type  authorization_code
Consumer Key  3MVG9e2mBbZnmxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxXe36YpUEhUi3ddV
Consumer Secret  436xxxxxxxxxxxxxxxxxx51
code                    aPrxr1wu_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxDSliVESA%3D%3D
redirect_uri            http://192.168.x.x:8080/sale_f/page.php




These are the parameters i am using !!
Ashish_SFDCAshish_SFDC
Hi  Suraj, 


In the line above it says "grand_type= authorization_code" where grant is spelled as Grand*** check if that is not the issue. 


Regards,
Ashish