Mohammad AL-Raoosh
Mohammad AL-Raoosh

Reputation: 731

How can I verify a LinkedIn access token?

How can I verify a LinkedIn access token?

I need to check if an access token is valid or not?

ex: in Facebook

https://graph.facebook.com/me?access_token=access_token

Is there a similar way to do it in LinkedIn?

Upvotes: 10

Views: 7538

Answers (5)

Zoha
Zoha

Reputation: 586

In case anyone is still looking for a solution:

You should use the Token Introspection API request.

curl --location --request POST 'https://www.linkedin.com/oauth/v2/introspectToken' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=<Application Client ID>' \
--data-urlencode 'client_secret=<Application Client Secret>' \
--data-urlencode 'token=<Token Value>'

For more details, see the link below:

Token Introspection Document

Keep in mind that verifying the token alone doesn't provide any user data. Typically, you'll need to use the access token to identify the user. For this, it's recommended to call the following API endpoint, which retrieves user information and will fail if the token is invalid or the user data is incorrect:

curl -X GET "https://api.linkedin.com/v2/userinfo" \
  -H "Authorization: Bearer <ACCESS_TOKEN>"

For more details, refer to the documentation: Retrieve Member Details

Upvotes: 0

pavittarx
pavittarx

Reputation: 191

The url has been changed and the v1 API does not work anymore. Do use this one, if you need to verify access tokens generated from Linkedin.

https://api.linkedin.com/v2/me?oauth2_access_token=<your-token-here>

For other social media's, use can use urls from this gist: https://gist.github.com/pavittarx/15b46b08e779c2113864e9db399f35ac

Upvotes: 1

Zeyvo
Zeyvo

Reputation: 11

You can use Token Introspection to get some informations about the token

https://learn.microsoft.com/en-us/linkedin/shared/authentication/token-introspection?context=linkedin/context

Upvotes: 1

lorena
lorena

Reputation: 31

Additionally, you can filter the values:

https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,picture-url,location,industry,current-share,num-connections,summary,specialties,positions)?format=json&oauth2_access_token={0}

Upvotes: 3

Mohammad AL-Raoosh
Mohammad AL-Raoosh

Reputation: 731

I found that it can be done like this:

https://api.linkedin.com/v1/people/~?oauth2_access_token=YOUR-ACCESS-TOKEN

and that's it :).

Upvotes: 11

Related Questions