1
votes

I have been trying with the simple REST Client as well as the REST Plugin for Mozilla. I am getting "HTTP/1.1 401 Unauthorized" response with "{"error":"unauthorized_client","error_description":"the client is not authorized"}" in the body.

I have been successful in getting the auth code, and the below is the POST request for access token, (Scope is r_fullprofile)

https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&code=AQTQeBxBzbU2aNWaQM6Ff3Z3bUd8Gyg10W9G2DdqXgWiP0q7-M55c5PLtppP7Ni3Y-6A9C8yDkj9K4VfJ7QkRUFjuV-3AknA5jAahpsFJv3wYfr8XD8&redirect_uri=https://www.google.com&client_id=75wl6j5zndvfkp&client_secret=secret

The redirect_uri=https://www.google.com is the one used for getting auth code as well.

Do we need to perform any URL encoding before making the POST request?

When I log into the linked in to my app, it has the below tokens, OAuth User Token: c3ae4cee-1b23-xxx-9d2a-206f578dee4d OAuth User Secret: 76bc48cc-c94f-xxx-bf9d-a663f7003383

I am not sure where it is used. we are using API & secret key to get auth code.

Thanks in Advance.

3

3 Answers

3
votes

This is a 2-step process.

First, go to:

https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=YOUR-API-ID&scope=r_basicprofile&state=STATE&redirect_uri=YOUR-ENCODED-REDIRECT-URI

Then, within 10 secs of receiving the response, go to:

https://www.linkedin.com/uas/oauth2/accessToken?grant_type=authorization_code&redirect_uri=YOUR-ENCODED-REDIRECT-URI&client_id=YOUR-API-ID&client_secret=YOUR-API-ID&code=THE-CODE-OBTAINED-IN-FIRST-STEP

The response of the second request will have the actual access token you need to use.

0
votes

When I followed the two steps I faced an issue where I got an error as {"errorCode":0,"message":"Access to posting shares denied","requestId":"TYWULO2WPZ","status":403,"timestamp":1497353538016}

So I had to remove the &scope=r_basicprofile since it was preventing reading all the Default Application Permissions

0
votes

I faced a similar problem and the problem was with the initial authorization code. You should mention the scope=rw_company_admin or whatever it is that you want to authorize to while doing the initial redirect URL call. Something like this -

https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=your_client_id&redirect_uri=https%3A%2F%2Fwww.google.com/&state=12345&scope=rw_company_admin%20r_emailaddress%20w_share%20r_basicprofile