Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including react-native-linkedin with all npm packages installed. Try it out:

var reactNativeLinkedin = require("react-native-linkedin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

react-native-linkedin v1.3.1

React-Native LinkedIn, a simple LinkedIn login library for React-Native with WebView and Modal

react-native-linkedin

🔗 React-Native LinkedIn

Simple LinkedIn login library for React-Native with WebView into a Modal


Demo on Expo


Benefits

  • Light: No need to link a native library like others alternatives
  • Simple: Get the token and the expires, you handle your own login with the access_token
  • Sure: open-source
  • Almost readable & understandable code: JavaScript & React

Installation

$ yarn add react-native-linkedin

Documentation

Props

NameTypeRequiredDefaultDescription
clientIDstringrequiredYour client id
clientSecretstringrequiredYour client secret
redirectUristringrequiredYour redirectUri
onSuccessfunctionrequiredFunction will be call back on success
authStatestringoptionalrequire('uuid').v4()The state of auth, to be more secure
onErrorfunctionoptionalconsole.error(err)Function will be call back on error
onClosefunctionoptionalFunction will be call back on close modal
onOpenfunctionoptionalFunction will be call back on open modal
onSignInfunctionoptionalFunction will be call back when the user sign in
permissionsarrayoptional['r_basicprofile', 'r_emailaddress']The LinkedIn access token permissions
renderButtonfunctionoptionalRender function for customize LinkedIn button
renderClosefunctionoptionalRender function for customize close button
linkTextstringoptional'Login with LinkedIn'Link label
containerStyleViewPropTypes.styleoptionalCustomize container style
wrapperStyleViewPropTypes.styleoptionalCustomize wrapper style
closeStyleViewPropTypes.styleoptionalCustomize close style
animationTypeModal.propTypes.animationTypeoptionalfadeCustomize animationType style: 'none', 'slide' or 'fade'
shouldGetAccessTokenbooloptionaltrueSet to false to receive the 'authorization code' rather then the 'access token'

Example

// See ./example folder for details
import React from 'react'
import { StyleSheet, View } from 'react-native'

import LinkedInModal from 'react-native-linkedin'

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    justifyContent: 'center',
    alignItems: 'center',
  },
})

export default class AppContainer extends React.Component {
  render() {
    return (
      <View style={styles.container}>
        <LinkedInModal
          clientID="[ Your client id from https://www.linkedin.com/developer/apps ]"
          clientSecret="[ Your client secret from https://www.linkedin.com/developer/apps ]"
          redirectUri="[ Your redirect uri set into https://www.linkedin.com/developer/apps ]"
          onSuccess={token => console.log(token)}
        />
      </View>
    )
  }
}

Security

Please note that you should give your linkedin client id and you secret key to the component. You should be aware that key can be found if you store it directly to your code. I strongly recommand to not declare both on your code but found a way to keep it secret (ie. get it from server, encrypt it, ...)

Roadmap & TODOs

  • [x] Better style for modal: border, padding, transparency
  • [x] Button to close the modal
  • [x] Better catch of error into login url
  • [x] Add gif example in README
  • [x] Publish example to expo
  • [ ] Test every line of code
  • [ ] Add props or other function to fetch more informations like basic profile information
  • [ ] Use Expo WebBrowser when app is in Expo (ie. if global.__exponent exist)

> Propose

Contribution

PRs are welcome!

FAQ

Is it supported and tested both on android and iOS?

YES

How to get the basic profile of a user after getting the token?

const access_token // from this lib
const baseApi = 'https://api.linkedin.com/v1/people/'
const params = [
  'first-name',
  'last-name',
  // add more fields here
]
const qs = { format: 'json' }

const response = await fetch(
  `${baseApi}~:(${params.join(',')})?${querystring.stringify(qs)}`,
  {
    method: 'GET',
    headers: {
      Authorization: 'Bearer ' + access_token
    }
  }
)
const payload = await response.json()

Other questions

Feel free to contact me or create an issue

Alternatives

Licence

MIT

made with ♥

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free