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

react-linkedin-oauth2

v1.0.8

Published

React component for Linked In Log In feature using OAuth 2.0

Downloads

38

Readme

React Linked In Login Using OAuth 2.0

npm package

Demo: https://stupefied-goldberg-b44ee5.netlify.com/

This package is used to get authorization code for Linked In Log in feature using OAuth2 in a easy way, without redirecting your application to linked in authorization page. After have the authorization code, you can send it to server to continue to get information needed. For more, please see at Authenticating with OAuth 2.0 - Linked In
See demo/src/index.js for examples.

Table of contents

Installation

npm i react-linkedin-oauth2

Overview

We will create a Linked In button (using LinkedIn component), after clicking on this button, a popup window will show up and ask for the permission. After we accepted, the pop up window will redirect to a specified URI which should be routed to LinkedInPopUp component. It has responsible to notice our openning app the authorization code Linked In provides us. You can consider using react-router-dom as a possible solution.

Usage

First, we create a button and provide required props

import React, { Component } from 'react';

import { LinkedIn } from 'react-linkedin-oauth2';

class LinkedInPage extends Component {
  state = {
    code: '',
    errorMessage: '',
  };


  handleSuccess = (data) => {
    this.setState({
      code: data.code,
      errorMessage: '',
    });
  }

  handleFailure = (error) => {
    this.setState({
      code: '',
      errorMessage: error.errorMessage,
    });
  }

  render() {
    const { code, errorMessage } = this.state;
    return (
      <div>
        <LinkedIn
          clientId="81lx5we2omq9xh"
          onFailure={this.handleFailure}
          onSuccess={this.handleSuccess}
          redirectUri="http://localhost:3000/linkedin"
        >
          <img src={require('./assets/linkedin.png')} alt="Log in with Linked In" style={{ maxWidth: '180px' }} />
        </LinkedIn>
        {!code && <div>No code</div>}
        {code && <div>Code: {code}</div>}
        {errorMessage && <div>{errorMessage}</div>}
      </div>
    );
  }
}

export default LinkedInPage;

Usage with custom button

<LinkedIn
  clientId="81lx5we2omq9xh"
  onFailure={this.handleFailure}
  onSuccess={this.handleSuccess}
  redirectUri="http://localhost:3000/linkedin"
  renderElement={({ onClick, disabled }) => (
    <button onClick={onClick} disabled={disabled}>Custom linkedin element</button>
  )}
/>

Then we define a route to redirect_url and pass LinkedInPopUp to it as follow:

import React, { Component } from 'react';
import { LinkedInPopUp } from 'react-linkedin-oauth2';

import { render } from 'react-dom';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import LinkedInPage from './LinkedInPage';

class Demo extends Component {
  render() {
    return (
      <BrowserRouter>
        <Switch >
          <Route exact path="/linkedin" component={LinkedInPopUp} />
          <Route path="/" component={LinkedInPage} />
        </Switch>
      </BrowserRouter>
    );
  }
}

Demo

You can see demo via this https://github.com/YBeck/react-linkedin-login-oauth2/tree/master/demo/src
Demo 1: Use react-router-dom
Demo 2: Not use react-router-dom
Or run

git clone https://github.com/YBeck/react-linkedin-login-oauth2.git
cd react-linkedin-login-oauth2
npm start

Props

LinkedIn component:

| Parameter | value | is required | default | | ------------- | -------- | :---------: | :-------------------------------------------------------------: | | clientId | string | yes | | | redirectUri | string | yes | | | scope | string | no | Default member permissions defined in application configuration | | state | string | no | fdsf78fyds7fm | | onSuccess | function | yes | | | onFailure | function | yes | | | className | string | no | 'btn-linkedin' | | disabled | boolean | no | false | | onClick | function | no | | | children | function | no | Linked in Signin button | | renderElement | function | no | Render prop to use a custom element, use props.onClick |

Read more about props here https://developer.linkedin.com/docs/oauth2

LinkedinPopUp component:
No parameters needed

Known issue

  • react-linkedin-oauth2 currently doesn't support IE 11.`

Credit

Based on react-linkedin-login-oauth2 by Hung Viet Nguyen