Skip to content

Instantly share code, notes, and snippets.

@officialrajdeepsingh
Created January 13, 2023 09:59
Show Gist options
  • Save officialrajdeepsingh/070b60e1564877136b1813fd2d940d03 to your computer and use it in GitHub Desktop.
Save officialrajdeepsingh/070b60e1564877136b1813fd2d940d03 to your computer and use it in GitHub Desktop.
Authorization Code Flow easy guideline for linkedin api. just replace your value and every think work fine.

I create a guideline for you how to create a authorization token by linkedin API

Requirements

  1. client_id (Require)
  2. redirect_uri (Require)
  3. scope (Require)
  4. response_type (The response_type value is always be code for example response_type: code)
  5. state (Random unique string read more in docs)
https://www.linkedin.com/oauth/v2/authorization? 
response_type=code&  
client_id=77*******oo&  
redirect_uri=https://example.com/auth/linkedin/callback&  state=RandomString&
scope=w_member_social,r_liteprofile

Step 1

https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=77*******oo&redirect_uri=http://localhost:3000/&state=foobar&scope=rw_organization_admin%20w_organization_social%20r_organization_social%20w_member_social%20r_member_social

Note: scope is allways convert to urlencoded without comman.

In the first step we recive two value code and state as responce by linkedin authorization API. We use code and state for step 2.

your response look like code vaild for 10 min or maybe less

http://localhost:3000/?code=AQRqdBOemLfrX_F1MPbWrzpEaLZC90QLyMiSmRz-rjqhWUp9eBVzNzvxGXzDC5pc2MINkmif4cY9tHqmHKvzEF9ZLvDRIqd6A_i-VT879D158uU1wNIt-w0d4gDlWmiHigqYsXQw0d4giHigqYsXQ&state=foobar

Step 2

For step 2 we need code and state paste code in code section

https://www.linkedin.com/oauth/v2/accessToken?Content-Type=application/x-www-form-urlencoded&grant_type=authorization_code&code=AQRqdBOemLfrX_F1MPbWrzpEaLZC90QLyMiSmRz-rjqhWUp9eBVzNzvxGXzDC5pc2MINkmif4cY9tHqmHKvzEF9ZLvDRIqd6A_i-VT879D158uU1wNIt-w0d4gDlWmiHigqYsXQ&redirect_uri=http://localhost:3000/&client_id=77*******oo

After you recevice your access token and refresh token, test it with following curl command.

curl -H "Authorization: Bearer <token>" \
"https://api.linkedin.com/v2/me?projection=(id)"

read more https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin%2Fmarketing%2Fcontext&view=li-lms-2022-12&tabs=HTTPS1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment