How to update LinkedIn authorization token

I have a grails application and I want to connect my account to my LinkedIn accounts.

So my steps are:

  • Ask the user to click the button that redirects to:

https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=MY_API_KEY&scope=r_network&state=SOME_TEXT&redirect_uri=MY_REDIRECT_URI

  • Then LinkedIn redirects to the specified redirect_uri, and I get the authorization code as a parameter in the response. With this code, I am making a message for:

https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=MY_AUTHORIZATION_CODE&redirect_uri=SAME_REDIREC_URI_AS_BEFORE&client_id=MY_API_KEY&client_secret=MYET_MER_

  • It works like a charm! I get the access token and save it in the user domain class along with the expiration date.

Now my problem arises when I want to have a piece of code with logic in order to update the access token before it expires, so as not to press a button on a button every time. I know applications in which you associate your account with LinkedIn and should never update the token again.

In the documentation: http://developer.linkedin.com/documents/handling-errors-invalid-tokens you can find a section called Updating Access Tokens , which reads:

Updating the access token is very simple and can occur without the authorization dialog box appearing for the user. In other words, this is a seamless process that does not affect the operation of your application.

Just ask the application to go through the authorization stream to get a new access token with an additional life expectancy of 60 days.

So, how can I follow the process described above if it starts with a user clicking a button.

I tried to make a GET using its HTTPClient class from groovy, as shown below:

new RESTClient(accessTokenRequestUrl, ContentType.URLENC) 

where accessTokenRequestUrl is the same as above in the href button. This will ultimately cause my redirect_uri, where I use the authorization code to request the access token, but it never reaches this point.

I tried using the RESTClient add-in for Firefox, and it works fine, but that is not the case if the call is made from within the application.

Any thoughts? Thanks in advance!

Greetings

Juan

+4
source share
1 answer

If you use the Linkedin JavaScript API, then the access token will be automatically updated without user intervention. Make sure that you set authorize: true in the initialization line so that the update is easily performed as follows:

 <script type="text/javascript" src="http://platform.linkedin.com/in.js"> api_key: YOUR_KEY_HERE authorize: true </script> 
+1
source

All Articles