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

@rahulsolanki_ct/linkedin-login

v1.0.5

Published

Package for Linked In Log In feature using OAuth 2.0

Downloads

10

Readme

Linked In Login Using OAuth 2.0

This package is used to get authorization code for Linked In Log in feature using OAuth2 in a easy way. After have the authorization code, you can exchange to an access token by sending it to the server to continue to get information needed. For more details, please see at Authorization Code Flow (3-legged OAuth) See Usage and Demo for instruction.

Table of contents

Installation

npm install @rahulsolanki_ct/linkedin-login

Overview

We will trigger linkedInLogin by using useLinkedIn (recommended) or LinkedIn (using render props technique) after click on Sign in with LinkedIn button, a popup window will show up and ask for the permission. After we accepted, the pop up window will redirect to redirectUri (should be LinkedInCallback component) then notice its opener about the authorization code Linked In provides us. You can use react-router-dom or Next.js's file system routing

Usage

First, we create a button and provide required props:

import React, { useState } from 'react';

import { useLinkedIn } from '@rahulsolanki_ct/linkedin-login';
// You can use provided image shipped by this package or using your own
import linkedin from '@rahulsolanki_ct/linkedin-login/assets/linkedin.png';

function LinkedInPage() {
  const { linkedInLogin } = useLinkedIn({
    clientId: '86vhj2q7ukf83q',
    redirectUri: `${window.location.origin}/linkedin`, // for Next.js, you can use `${typeof window === 'object' && window.location.origin}/linkedin`
    onSuccess: (code) => {
      console.log(code);
    },
    onError: (error) => {
      console.log(error);
    },
  });

  return (
    <img
      onClick={linkedInLogin}
      src={linkedin}
      alt="Sign in with Linked In"
      style={{ maxWidth: '180px', cursor: 'pointer' }}
    />
  );
}

If you don't want to use hooks. This library offer render props option:

import React, { useState } from 'react';

import { LinkedIn } from '@rahulsolanki_ct/linkedin-login';
// You can use provided image shipped by this package or using your own
import linkedin from '@rahulsolanki_ct/linkedin-login/assets/linkedin.png';

function LinkedInPage() {
  return (
    <LinkedIn
      clientId="86vhj2q7ukf83q"
      redirectUri={`${window.location.origin}/linkedin`}
      onSuccess={(code) => {
        console.log(code);
      }}
      onError={(error) => {
        console.log(error);
      }}
    >
      {({ linkedInLogin }) => (
        <img
          onClick={linkedInLogin}
          src={linkedin}
          alt="Sign in with Linked In"
          style={{ maxWidth: '180px', cursor: 'pointer' }}
        />
      )}
    </LinkedIn>
  );
}

Then we point redirect_url to LinkedInCallback. You can use react-router-dom or Next.js's file system routing

  • react-router-dom:
import React from 'react';
import { LinkedInCallback } from '@rahulsolanki_ct/linkedin-login';

import { BrowserRouter, Route } from 'react-router-dom';

function Demo() {
  return (
    <BrowserRouter>
      <Route exact path="/linkedin" component={LinkedInCallback} />
    </BrowserRouter>
  );
}
  • Next.js's file system routing:
// pages/linkedin.js
import { LinkedInCallback } from '@rahulsolanki_ct/linkedin-login';
export default function LinkedInPage() {
  return <LinkedInCallback />;
}

Props

  • LinkedIn component:

| Parameter | value | is required | default | | ----------- | -------- | :---------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | clientId | string | yes | | | redirectUri | string | yes | | | onSuccess | function | yes | | | onError | function | no | | | state | string | no | randomly generated string (recommend to keep default value) | | scope | string | no | 'r_emailaddress' | | | | | See your app scope here. If there are more than one, delimited by a space | | children | function | no | Require if using LinkedIn component (render props) |

Reference: https://docs.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context#step-2-request-an-authorization-code

  • LinkedInCallback component: No parameters needed