mgi1985
mgi1985

Reputation: 33

Linkedin OAuth2 authorization code error

I´m trying to connect via Linkedin Auth2 from a java web application:

  1. Added my own app in linkedin.
  2. Generate the authorization URL: https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=XXX&scope=r_basicprofile%20r_fullprofile%20r_emailaddress&state=DCEEFWF454Us5dffef424&redirect_uri=http://localhost:9090/springmvc/token.htm
  3. Introduce my login/password for linkedin in the new popup.
  4. Get back successful the request on the redirect_uri previus, and take the authorization code "code"
  5. Generate the accessToken URL
  6. Make a POST with: https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=YYY&redirect_uri=http://localhost:9090/SpringMVC/token.htm&client_id=XXX&client_secret=ZZZ
  7. Get next error in response: {"error_description":"missing required parameters, includes an invalid parameter value, parameter more than once. : Unable to retrieve access token : appId or redirect uri does not match authorization code or authorization code expired","error":"invalid_request"}

I´ve verified url parameters are correct: - "code" is the token receive on step 4.

Upvotes: 3

Views: 9911

Answers (3)

Roshan
Roshan

Reputation: 77

If You Are Sending a Request For Access Token it must be POST Request

Refer the OAuth Documentation

I actually Copied the Whole URL From My Eclipse Console To URL It is Still Valid

In Your Case The Problem is with URL Encoding As HanZ said . You Have to Encode Your URL For Post Request.

Upvotes: 1

Juvenik
Juvenik

Reputation: 950

I too got bugged with this issue for long time. Please keep few things in mind which I did and eventually sorted it out.

  1. Hit the api to get authorization code by using get request.
  2. The authorization code has a life span of about 20 seconds, so its difficult to manually copy the code from the url and make a request for token access. You should do it pro-grammatically.
  3. Make a post request for getting access token.
  4. Most Important: Old linkedin applications that I had created was not working and giving the above error. Create a new linkedin application and try. Doing this worked for me.

I assume that all the other parameters like client_id, secret, redirect_uri are correct.

please try and let us know.

Thanks.

Upvotes: 0

Hans Z.
Hans Z.

Reputation: 53888

The value of your redirect_uri parameter must be URL-encoded, so at 6. do:

 https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=YYY&redirect_uri=http%3A%2F%2Flocalhost%3A9090%2FSpringMVC%2Ftoken.htm&client_id=XXX&client_secret=ZZZ

and it need not be sent as a POST but as a GET.

Upvotes: 4

Related Questions