LinkedIn OAuth Setup Guide
This comprehensive guide explains the LinkedIn OAuth 2.0 flow and how to obtain all required credentials for posting.
What You'll Need
To post to LinkedIn, you need 6 credentials:
- Client ID - Identifies your OAuth app
- Client Secret - Proves your app's authenticity
- Access Token - Authorizes API requests
- Refresh Token - Renews expired access tokens (mandatory)
- Person ID - Your LinkedIn profile identifier
- Organization ID - Company page identifier (optional)
Using Multiple LinkedIn Apps
Good news: If you already have LinkedIn OAuth apps registered, you can use any one of them to post to your personal profile!
- Your Person ID stays the same regardless of which app you use
- Each app has its own Client ID and Client Secret - just pick one app and use its credentials
- The app only needs proper permissions (w_member_social) and authorization from you
- Posts always go to your personal profile when you specify your Person ID as the author
You don't need to create a new app - simply choose any existing app that has "Share on LinkedIn" access approved, complete the OAuth flow for that app, and use its credentials here.
Understanding the OAuth Flow
LinkedIn uses OAuth 2.0 for authentication. Here's how each credential is obtained and used in the posting flow:
| Stage | Credentials Needed | Purpose |
|---|---|---|
| App Registration | Client ID, Client Secret | Register and identify your OAuth app |
| OAuth Initiation | Client ID, Redirect URI | Start OAuth flow and direct user consent |
| Authorization | Authorization Code | Temporary credential after user approves access |
| Token Exchange | Client ID, Client Secret, Auth Code | Obtain access and refresh tokens |
| API Posting | Access Token, Person ID | Authorize requests and specify post author |
| Token Renewal | Refresh Token, Client ID, Client Secret | Renew access tokens for continued posting |
Step 1: Create a LinkedIn OAuth App
- Go to LinkedIn Developer Portal and sign in
- Click "Create app"
- Fill in the required information:
- App name: Choose a descriptive name (e.g., "My LinkedIn Poster")
- LinkedIn Page: Select or create a company page (required by LinkedIn)
- App logo: Upload a logo (minimum 100x100px)
- Legal agreement: Accept LinkedIn's API Terms of Use
- Click "Create app"
Note: After creating your app, you'll see your Client ID and Client Secret in the "Auth" tab. Save these securely - you'll need them later.
Step 2: Configure OAuth Settings
- In your app dashboard, go to the "Auth" tab
- Under "OAuth 2.0 settings", add redirect URLs:
- For this app:
https://yourdomain.com/api/auth/linkedin/callback
Replaceyourdomain.comwith your actual domain. The exact URL will be shown in the LinkedIn settings section when you're ready to connect. - For testing with Postman:
https://oauth.pstmn.io/v1/callback
- For this app:
- Click "Update"
Critical: The redirect URI must be added to your LinkedIn app settings before you attempt to connect. If you get a "redirect_uri does not match" error, verify that the exact URL (including https://) is configured in your LinkedIn app's Auth tab.
Step 3: Request Product Access
- Go to the "Products" tab in your app dashboard
- Request access to these products:
- Sign In with LinkedIn using OpenID Connect - Usually approved instantly
- Share on LinkedIn - Required for posting (may require review)
- Advertising API - Optional, for company page posting
- Wait for approval (instant for Sign In, may take 1-2 days for Share on LinkedIn)
Important: You cannot post to LinkedIn until "Share on LinkedIn" is approved. Check your email for approval notifications.
Step 4: Generate Access and Refresh Tokens
You need to complete the OAuth 2.0 flow to obtain your access token and refresh token. Here are two methods:
Method 1: Using Postman (Recommended for Beginners)
- Download and install Postman
- Create a new request
- Go to the "Authorization" tab
- Select "OAuth 2.0" as the type
- Grant Type: Authorization Code
- Callback URL:
https://oauth.pstmn.io/v1/callback - Auth URL:
https://www.linkedin.com/oauth/v2/authorization - Access Token URL:
https://www.linkedin.com/oauth/v2/accessToken - Client ID: Your app's Client ID
- Client Secret: Your app's Client Secret
- Scope:
openid profile email w_member_social
- Click "Get New Access Token"
- Authorize the app in the LinkedIn popup
- Copy the access_token and refresh_token from the response
Method 2: Manual OAuth Flow (Advanced)
- Build the authorization URL:
https://www.linkedin.com/oauth/v2/authorization? response_type=code &client_id=YOUR_CLIENT_ID &redirect_uri=YOUR_REDIRECT_URI &scope=openid%20profile%20email%20w_member_social - Open this URL in a browser and authorize the app
- LinkedIn will redirect you with an authorization code in the URL
- Exchange the code for tokens:
curl -X POST 'https://www.linkedin.com/oauth/v2/accessToken' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'grant_type=authorization_code' \ -d 'code=YOUR_AUTH_CODE' \ -d 'client_id=YOUR_CLIENT_ID' \ -d 'client_secret=YOUR_CLIENT_SECRET' \ -d 'redirect_uri=YOUR_REDIRECT_URI' - Save the
access_tokenandrefresh_tokenfrom the response
Step 5: Get Your Person ID
Use your access token to retrieve your LinkedIn Person ID:
curl -X GET 'https://api.linkedin.com/v2/userinfo' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'The sub field in the response contains your Person ID (e.g., uVzUQ8CUU9). This is used to identify you as the post author.
Step 6: Get Your Organization ID (Optional)
If you want to post as a company page, get your Organization ID:
Organization Posting Requirements
To post to company pages, you need additional setup:
- Add "Community Management API" Product - Go to your LinkedIn app → Products tab → Request access to "Community Management API" (this provides r_organization_social and w_organization_social permissions)
- Wait for Approval - Usually instant for verified apps, may take 1-2 days for review
- You Must Be an ADMINISTRATOR - You need admin access to the company page, not just member access
- Re-authorize After Adding Permissions - If you already connected LinkedIn before adding these permissions, disconnect and reconnect to get a new access token with organization permissions
curl -X GET 'https://api.linkedin.com/v2/organizationAcls?q=roleAssignee' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'Find your organization's ID in the response (e.g., 104469861). You must have admin access to the company page.
Common Issue: If you get a 403 ACCESS_DENIED error when fetching organizations, it means either: (1) Your LinkedIn app doesn't have "Community Management API" product added, (2) You need to re-authorize to get a new access token with the updated permissions, or (3) You're not an ADMINISTRATOR of any organizations.
Step 7: Add Credentials to the App
- Go to Settings in this app
- Scroll to the LinkedIn section
- Enter all 6 credentials in order:
- Client ID
- Client Secret
- Access Token
- Refresh Token (mandatory)
- Person ID
- Organization ID (optional)
- Click "Save LinkedIn Credentials"
Required OAuth Scopes
When generating your access token, you must request these scopes:
openid- Basic authenticationprofile- Access to profile informationemail- Access to email addressw_member_social- Required for posting to personal profilew_organization_social- Required only for company page posting
Token Expiration and Refresh
Access tokens expire after 60 days. This is why the refresh token is mandatory. When your access token expires, the app automatically uses your refresh token (along with your client ID and secret) to obtain a new access token without requiring you to re-authenticate.
Pro Tip: Refresh tokens are long-lived (typically 1 year) and can be used multiple times. Always save your refresh token securely!
Troubleshooting
"Invalid redirect_uri" error
Ensure your redirect URI in the OAuth request exactly matches one of the redirect URIs configured in your LinkedIn app settings (case-sensitive, including trailing slashes).
"Insufficient permissions" error
Verify that "Share on LinkedIn" product access has been approved for your app. Check the "Products" tab in your LinkedIn app dashboard.
"Token expired" error
Your access token has expired. If you provided a refresh token, the app will automatically renew it. If not, you'll need to generate a new access token through the OAuth flow.
"client_id is required" error
This means your Client ID or Client Secret is missing or incorrect. Double-check that you've entered both credentials correctly in the settings.
"ACCESS_DENIED" for organizations
This error occurs when trying to fetch organization IDs. To fix:
- Add Community Management API Product: Go to your LinkedIn app → Products tab → Request "Community Management API" (not just the permission scope)
- Wait for Approval: Check your email for approval notification (usually instant)
- Re-authorize: Disconnect and reconnect your LinkedIn account in Settings to get a new access token with organization permissions
- Verify Admin Access: Ensure you're an ADMINISTRATOR (not just a member) of the organizations you want to access
Note: The access token issued before adding permissions won't include organization access. You must re-authorize to get a new token.
API Rate Limits
LinkedIn enforces the following rate limits:
- Personal posts: 100 posts per day per user
- Company posts: 250 posts per day per organization
- API calls: Varies by product, typically 500 requests per day
Security Best Practices
- Never share your Client Secret - Treat it like a password
- Store tokens securely - Never commit them to version control
- Use HTTPS - Always use secure connections for OAuth flows
- Rotate credentials - If compromised, regenerate your Client Secret immediately
- Monitor usage - Keep track of API calls to stay within rate limits