Back to Settings

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:

  1. Client ID - Identifies your OAuth app
  2. Client Secret - Proves your app's authenticity
  3. Access Token - Authorizes API requests
  4. Refresh Token - Renews expired access tokens (mandatory)
  5. Person ID - Your LinkedIn profile identifier
  6. 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:

StageCredentials NeededPurpose
App RegistrationClient ID, Client SecretRegister and identify your OAuth app
OAuth InitiationClient ID, Redirect URIStart OAuth flow and direct user consent
AuthorizationAuthorization CodeTemporary credential after user approves access
Token ExchangeClient ID, Client Secret, Auth CodeObtain access and refresh tokens
API PostingAccess Token, Person IDAuthorize requests and specify post author
Token RenewalRefresh Token, Client ID, Client SecretRenew access tokens for continued posting

Step 1: Create a LinkedIn OAuth App

  1. Go to LinkedIn Developer Portal and sign in
  2. Click "Create app"
  3. 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
  4. 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

  1. In your app dashboard, go to the "Auth" tab
  2. Under "OAuth 2.0 settings", add redirect URLs:
    • For this app: https://yourdomain.com/api/auth/linkedin/callback
      Replace yourdomain.com with 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
  3. 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

  1. Go to the "Products" tab in your app dashboard
  2. 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
  3. 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)

  1. Download and install Postman
  2. Create a new request
  3. Go to the "Authorization" tab
  4. 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
  5. Click "Get New Access Token"
  6. Authorize the app in the LinkedIn popup
  7. Copy the access_token and refresh_token from the response

Method 2: Manual OAuth Flow (Advanced)

  1. 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
  2. Open this URL in a browser and authorize the app
  3. LinkedIn will redirect you with an authorization code in the URL
  4. 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'
  5. Save the access_token and refresh_token from 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:

  1. 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)
  2. Wait for Approval - Usually instant for verified apps, may take 1-2 days for review
  3. You Must Be an ADMINISTRATOR - You need admin access to the company page, not just member access
  4. 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

  1. Go to Settings in this app
  2. Scroll to the LinkedIn section
  3. Enter all 6 credentials in order:
    1. Client ID
    2. Client Secret
    3. Access Token
    4. Refresh Token (mandatory)
    5. Person ID
    6. Organization ID (optional)
  4. Click "Save LinkedIn Credentials"

Required OAuth Scopes

When generating your access token, you must request these scopes:

  • openid - Basic authentication
  • profile - Access to profile information
  • email - Access to email address
  • w_member_social - Required for posting to personal profile
  • w_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:

  1. Add Community Management API Product: Go to your LinkedIn app → Products tab → Request "Community Management API" (not just the permission scope)
  2. Wait for Approval: Check your email for approval notification (usually instant)
  3. Re-authorize: Disconnect and reconnect your LinkedIn account in Settings to get a new access token with organization permissions
  4. 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

  1. Never share your Client Secret - Treat it like a password
  2. Store tokens securely - Never commit them to version control
  3. Use HTTPS - Always use secure connections for OAuth flows
  4. Rotate credentials - If compromised, regenerate your Client Secret immediately
  5. Monitor usage - Keep track of API calls to stay within rate limits

Additional Resources