• VenkatGP
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies

How do we validate an access token for validity using REST API (to check if access token has expired)?

Hi,
 
I am trying to create a User on SalesForce programmatically using the SF RESTful API's. So for the same, I submit a http post request to the URL https://login.salesforce.com/services/oauth2/authorize. I also pass the required parameters like username, password, response_type, client_id and redirect_uri. I am able to successfully login, but SF responds with the "code" by re-directing to the callback URL configured in the Remote Access, which means my program does not directly receive the code by a response.
 
The approach I could think of is as follows:-
1. Whenever my program gets a request to create User on SF, it will try to retrieve the access token from my local cache.
2. If access token is not found in cache, then my program is put on hold. I would do a programmatic login as described above and have a RESTful API exposed on my server (which is accessible by SF). The callback URL is pointed to this RESTful API. So my RESTful API receives the code from SF and retrives the access token using SF's RESTful API. The retrieved access token is cached in my local cache which can be re-used for further RESTful API access until it times out.
3. The program has to wait and will resume on retrieving the access token and the User is created on SF using RESTful API.
 
Can someone please let me know if the same can be achieved in a better way or if SF already has some mechanism which I could use.
Thanks in advance.

 

Regards,
VenkatGP

How do we validate an access token for validity using REST API (to check if access token has expired)?

Hi,
 
I am trying to create a User on SalesForce programmatically using the SF RESTful API's. So for the same, I submit a http post request to the URL https://login.salesforce.com/services/oauth2/authorize. I also pass the required parameters like username, password, response_type, client_id and redirect_uri. I am able to successfully login, but SF responds with the "code" by re-directing to the callback URL configured in the Remote Access, which means my program does not directly receive the code by a response.
 
The approach I could think of is as follows:-
1. Whenever my program gets a request to create User on SF, it will try to retrieve the access token from my local cache.
2. If access token is not found in cache, then my program is put on hold. I would do a programmatic login as described above and have a RESTful API exposed on my server (which is accessible by SF). The callback URL is pointed to this RESTful API. So my RESTful API receives the code from SF and retrives the access token using SF's RESTful API. The retrieved access token is cached in my local cache which can be re-used for further RESTful API access until it times out.
3. The program has to wait and will resume on retrieving the access token and the User is created on SF using RESTful API.
 
Can someone please let me know if the same can be achieved in a better way or if SF already has some mechanism which I could use.
Thanks in advance.

 

Regards,
VenkatGP