Strapi plugin logo for Linkedin Auth

Linkedin Auth

Using this plugin, you can create a social login with LinkedIn in Strapi. This plugin supports the latest LinkedIn permissions, including OpenID, profile, and email.

thumbnail for Linkedin Auth

Social Login using LinkedIn Plugin for Strapi

Introduction

This plugin enables LinkedIn social login using OpenID Connect in Strapi. It handles the OAuth 2.0 authorization flow, retrieves user information from LinkedIn, and creates or updates the user in Strapi's database.

Installation

  1. Install our plugin into your Strapi project:

npm install strapi-linkedin-auth

  1. Install required dependencies:

npm install

npm install axios react-icons

  1. Set up environment variables:

Add the following to your .env file:

1LINKEDIN_CLIENT_ID=<your-client-id>
2LINKEDIN_CLIENT_SECRET=<your-client-secret>
3REDIRECT_URI=<your-redirect-uri>

Your ".env" file should look like this:

HOST=0.0.0.0
PORT=1337
APP_KEYS=your_app_key_1,your_app_key_2,your_app_key_3,your_app_key_4
API_TOKEN_SALT=your_api_token_salt
ADMIN_JWT_SECRET=your_admin_jwt_secret
TRANSFER_TOKEN_SALT=your_transfer_token_salt
# Database
DATABASE_CLIENT=sqlite
DATABASE_FILENAME=.tmp/data.db

JWT_SECRET=your_jwt_secret

LINKEDIN_CLIENT_ID= your_client_id
LINKEDIN_CLIENT_SECRET= your_client_secret
REDIRECT_URI = your_redirect_url

Your "root folder config/plugins.js" should look like this:

module.exports = {
  "linkedin-auth": {
    enabled: true,
    resolve: "./src/plugins/linkedin-auth",
  },
};

Plugin Structure

  • linkedin-auth/admin/src/pages/homepage/index.js: frontend component for LinkedIn login in the Strapi admin panel.
  • linkedin-auth/server/controllers/linkedin-auth.js: Handles LinkedIn OAuth flow and user creation/updating.
  • linkedin-auth/server/routes/index.js: Defines API routes for LinkedIn authentication.

Endpoints

  • GET /linkedin-auth/linkedin-config: Fetch LinkedIn client ID and redirect URI.
  • POST /linkedin-auth/token: Exchange authorization code for access token and retrieve user info.

LinkedIn's Endpoints that we have used:

Handling LinkedIn Sign-In:

1const handleLinkedInSignIn = () => {
2  const url = `https://www.linkedin.com/oauth/v2/authorization?client_id=${clientId}&redirect_uri=${redirectUri}&response_type=code&scope=openid%20profile%20email`;
3  window.location.href = url;
4};

Exchanging Authorization Code for Token:

1const response = await axios.post(
2  "https://www.linkedin.com/oauth/v2/accessToken",
3  new URLSearchParams({
4    grant_type: "authorization_code",
5    code: code,
6    redirect_uri: process.env.REDIRECT_URI,
7    client_id: process.env.LINKEDIN_CLIENT_ID,
8    client_secret: process.env.LINKEDIN_CLIENT_SECRET,
9  }).toString(),
10  {
11    headers: {
12      "Content-Type": "application/x-www-form-urlencoded",
13    },
14    httpsAgent,
15  }
16);
17
18const accessToken = response.data.access_token;

Required Permissions

  • openid: Authenticate the user.
  • profile: Retrieve the user's LinkedIn profile.
  • email: Retrieve the user's email address.

Response Data

After successful LinkedIn login, the following data is returned:

1{
2  "isValid": true,
3  "message": "LinkedIn validated successfully, user created or exists",
4  "jwt": "<jwt-token>",
5  "user": {
6    "id": "<user-id>",
7    "username": "<user-name>",
8    "email": "<user-email>"
9  }
10}

Usage

  1. Start Strapi:

npm run develop

  1. Navigate to the LinkedIn login page in the Strapi admin panel.

  2. Click on "Sign in with LinkedIn" to initiate the login process.

  3. After successful authentication, the user will be created or updated in the Strapi database, and a JWT token will be issued.

Additional Information

(https://learn.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin-v2?context=linkedin%2Fconsumer%2Fcontext) and (https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication?context=linkedin/context)

Flow Diagram

Here is the LinkedIn Flow Diagram:

LinkedIn Flow Diagram

Video Demonstrations

React Frontend

React Frontend

  • Filename: sample_react_frontend.mp4
  • Description: Demonstrates the React frontend setup.

Strapi Homepage Frontend

Strapi Homepage Frontend

  • Filename: sample_strapi_homepage_frontend.mp4
  • Description: Shows the frontend for the Strapi homepage.

Normal Login Strapi Homepage

Normal Login Strapi Homepage

  • Filename: normal_login_strapi_homepage.mp4
  • Description: Demonstrates the normal login functionality on the Strapi homepage.

GitHub Repository

You can find the source code and contribute to the project on GitHub: strapi-linkedin-auth

Contributing

We welcome contributions to this plugin. If you have any improvements or bug fixes, please open an issue or submit a pull request on the GitHub repository.

Install now

npm install strapi-linkedin-auth

STATS

No GitHub star yet4 weekly downloads

Last updated

121 days ago

Strapi Version

4.0.0 and above

Author

github profile image for Madhan Adithya, Revanth Bollepalli
Madhan Adithya, Revanth Bollepalli

Useful links

Create your own plugin

Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.