npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

strapi-linkedin-auth

v1.0.0

Published

This plugin enables users to integrate Linked In social login using OpenId in strapi.

Downloads

142

Readme

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:

LINKEDIN_CLIENT_ID=<your-client-id>
LINKEDIN_CLIENT_SECRET=<your-client-secret>
REDIRECT_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:

  • POST "authorization_endpoint": "https://www.linkedin.com/oauth/v2/authorization".
  • POST "token_endpoint": "https://www.linkedin.com/oauth/v2/accessToken".
  • GET "userinfo_endpoint": "https://api.linkedin.com/v2/userinfo".

Handling LinkedIn Sign-In:

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

Exchanging Authorization Code for Token:

const response = await axios.post(
  "https://www.linkedin.com/oauth/v2/accessToken",
  new URLSearchParams({
    grant_type: "authorization_code",
    code: code,
    redirect_uri: process.env.REDIRECT_URI,
    client_id: process.env.LINKEDIN_CLIENT_ID,
    client_secret: process.env.LINKEDIN_CLIENT_SECRET,
  }).toString(),
  {
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    httpsAgent,
  }
);

const 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:

{
  "isValid": true,
  "message": "LinkedIn validated successfully, user created or exists",
  "jwt": "<jwt-token>",
  "user": {
    "id": "<user-id>",
    "username": "<user-name>",
    "email": "<user-email>"
  }
}

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

  • LinkedIn API Documentation: [Sign In with LinkedIn using OpenID Connect]

(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.