Linkedin OAuth2 ๐Ÿ”‘ Guide


๐Ÿ”„ Resources


๐Ÿ”ง LinkedIn OAuth2 App Setup Guide

Step 1: Create a LinkedIn Developer Account

  1. Log in with your LinkedIn account or create one if you don't have it.

Step 2: Create a LinkedIn App

  1. Click on Create App.

  2. Fill in all basic details.

  3. Associate your app with a company page (create one if you donโ€™t have any).

Create App
Create Company Page

Step 3: Verify the LinkedIn App

  1. Request app verification via the Settings > Verify button.

  2. Paste the verification link into a new browser window.

  3. Press Verify.

Verify App

Step 4: Client ID and Client Secret

  • Access Client ID and Secret from the Auth tab in the developer dashboard.

  • Go to the Products tab and request access to Sign In with LinkedIn using OpenID Connect and Share on LinkedIn.

Auth Tab
Scopes
Display Scopes

๐Ÿšจ Important: LinkedIn servers will only communicate with trusted URLs. Ensure your callback URL meets the following criteria:

  • Must be absolute: https://example.com/auth/linkedin/callback

  • Parameters are ignored: https://example.com/auth/linkedin/callback?id=1 becomes https://example.com/auth/linkedin/callback

  • Cannot include a #: https://example.com/auth/linkedin/callback#linkedin is invalid.

Step 6: Store Credentials Securely

๐Ÿ”’ Tip: Use a .env file for secure storage of credentials.

LINKEDIN_CLIENT_ID='๐Ÿ”‘ your-client-id'
LINKEDIN_CLIENT_SECRET='๐Ÿ”’ your-client-secret'
LINKEDIN_REDIRECT_URI='๐ŸŒ your-redirect-uri'
LINKEDIN_SCOPE=openid,profile,w_member_social,email

๐Ÿš€ Getting Started

Import LinkedIn Class and Configure Settings

from omni_authify.providers import LinkedIn

linkedin_provider = LinkedIn(
    client_id='๐Ÿ”‘ your-linkedin-client-id',
    client_secret='๐Ÿ”’ your-linkedin-client-secret',
    redirect_uri='๐ŸŒ your-linkedin-redirect-uri',
    scope='openid,profile,w_member_social,email'
)

Ensure your redirect_uri matches the callback URL in both LinkedIn app settings and Django URLs.


๐Ÿ—Š Methods

1. ๐Ÿ”— Get Authorization URL

Generates the login URL for LinkedIn authentication.

def get_authorization_url(state=None):
    pass

Example:

auth_url = linkedin_provider.get_authorization_url(state='random_state_string')

2. ๐Ÿ”“ Get Access Token

Exchanges the authorization code for an access token.

def get_access_token(code):
    pass

Example:

access_token = linkedin_provider.get_access_token(code='authorization_code')

3. ๐Ÿ•ด๏ธ Get User Profile

Fetches the authenticated userโ€™s profile data.

def get_user_profile(access_token):
    pass

Example:

user_info = linkedin_provider.get_user_profile(access_token)

โœ… Best Practices

  • ๐Ÿ”’ Secure Credentials: Use environment variables to protect sensitive data.

  • ๐Ÿ”— Match Redirect URI: Ensure consistency between LinkedIn app settings and your application code.

  • โš ๏ธ Handle Errors Gracefully: Implement error handling for a smooth user experience.


๐ŸŽ‰ Final Result

Consent Page
Login Page

Last updated

Was this helpful?