Socket
Socket
Sign inDemoInstall

nr-linkedin-login

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nr-linkedin-login

A cordova linkedin plugin with native login style


Version published
Weekly downloads
8
increased by300%
Maintainers
1
Install size
25.3 kB
Created
Weekly downloads
 

Readme

Source

LinkedIn

$ cordova plugin add  https://github.com/nithinkumarhere/nr-cordova-linkedin.git --variable APP_ID=YOUR_APP_ID
$ npm install --save nr-linkedin-login

[Usage Documentation]

Plugin Repo: https://github.com/nithinkumarhere/nr-cordova-linkedin

A Cordova plugin that lets you use LinkedIn Native SDKs for Android and iOS.

Please see the plugin's repo for detailed installation steps.

Supported platforms

  • Android
  • iOS

Usage for Linkedin Login for Native

import { LinkedIn } from '@ionic-native/linkedin';

constructor(private linkedin: LinkedIn) { }

...

// check if there is an active session
this.linkedin.hasActiveSession().then((active) => console.log('has active session?', active));

// login
const scopes = ['r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share'];
this.linkedin.login(scopes, true)
  .then(() => console.log('Logged in!')
  .catch(e => console.log('Error logging in', e));


// get connections
this.linkedin.getRequest('people/~')
  .then(res => console.log(res))
  .catch(e => console.log(e));

// share something on profile
const body = {
  comment: 'Hello world!',
  visibility: {
    code: 'anyone'
  }
};

this.linkedin.postRequest('~/shares', body)
  .then(res => console.log(res))
  .catch(e => console.log(e));

Linkedin Login for In-App-Browser in case Linkedin App is not installed

Installing

From the root of your Apache Cordova project, execute the following:

npm install nr-linkedin-browser --save

This will install nr-linkedin-browser and its dependencies.

Injecting:

There are 2 types of entities in the library: Platform (i.e., Cordova, Browser) and Provider (i.e., Facebook, LinkedIn, etc.). Each provider has it's own class. You need to inject the Platform class into every class in which you wish to use them. For example, if you wish to use Facebook oauth in a particular class, it would look something like:

import {LinkedInb} from 'nr-linkedin-browser/core';
import {OauthBrowser} from 'nr-linkedin-browser/platform/browser'
// or
import {OauthCordova} from 'nr-linkedin-browser/platform/cordova'

Alternatively you can use Angular2 Injector in order to provide platform specific service for all components:

import {bootstrap} from '@angular/platform-browser-dynamic'
import {App} from './app.component'
import {OauthCordova} from 'nr-linkedin-browser/platform/cordova'
import {Oauth} from 'nr-linkedin-browser/oauth'

bootstrap(App, [
  { provide: Oauth, useClass: OauthCordova }
])

// and later in component

@Component({
  selector: 'my-component'
})
class MyComponent {
  constructor(oauth: Oauth) {
    this.oauth = oauth
  }
}

Using nr-linkedin-browser In Your Project

const provider = new LinkedInb({
    clientId: string,
    appScope?: string[],
    redirectUri?: string,
    responseType?: string,
    authType?: string
});

A Working Example with both Native & In-App-Browser, If Linkedin App is not installed locally it should trigger In-App-Browser login.

import { Component, OnInit } from '@angular/core';
import { NavController, Platform } from 'ionic-angular';
import { LinkedIn, LinkedInLoginScopes } from 'nr-linkedin';
import { LinkedInb } from "nr-linkedin-browser/core";
import {OauthCordova} from 'nr-linkedin-browser/platform/cordova';
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage implements OnInit {

private loggedIn: boolean;
  scopes: LinkedInLoginScopes[] = ['r_basicprofile', 'r_emailaddress', 'rw_company_admin', 'w_share'];
  isLoggedIn: boolean = false;
  selfData = { id:"", firstName:"", lastName:"" };

  private oauth: OauthCordova = new OauthCordova();
  private linkedinbProvider: LinkedInb = new LinkedInb({
    clientId: "814imsl6ap5wcn",
    appScope: ["r_basicprofile","r_emailaddress"],
    redirectUri: "http://localhost/callback",
    responseType: "code",
    state: "DCEeFWf45A53sdfKef424"
  })
   constructor(public navCtrl: NavController, private linkedin: LinkedIn, private platform: Platform) {}
   public linkedinb() {
    this.platform.ready().then(() => {
        this.oauth.logInVia(this.linkedinbProvider).then(success => {
            console.log("RESULT: " + JSON.stringify(success));

        }, error => {
            console.log("ERROR: ", error);
        });
    });
}
  ngOnInit() {

  }

  ionViewDidAppear() {
    this.linkedin.hasActiveSession().then((active) => {
      this.isLoggedIn = active;
      if(this.isLoggedIn === true) {
        this.getSelfData();
      }
    });
  }


  login(){
  this.linkedin.isLinkedInAppInstalled()
  .then(res => {
    if(res==false){
      console.log("app not installed");
      this.linkedinb();
    }else{
      console.log("app installed");
      this.linkedin.login(this.scopes, true)
      .then(() => {
        this.isLoggedIn = true;
        this.getSelfData();
      })
      .catch(e => console.log('Error logging in', e));
    }
  })
  .catch(e => console.log(e));
}



  logout() {
    this.linkedin.logout();
    this.isLoggedIn = false;
    console.log(this.isLoggedIn);
  }

  getSelfData() {
    this.linkedin.getRequest('people/~')
      .then(res => {
        this.selfData = res;
        //this.openProfile(res.id);
        console.log(res);
      })
      .catch(e => console.log(e));
  }

  openProfile(memberId) {
    this.linkedin.openProfile(memberId)
      .then(res => console.log(res))
      .catch(e => console.log(e));
  }

  shareSomething() {
    const body = {
      comment: 'May I Share something on my profile?',
      visibility: {
        code: 'anyone'
      }
    };

    this.linkedin.postRequest('~/shares', body)
      .then(res => console.log(res))
      .catch(e => console.log(e));
  }
}

Keywords

FAQs

Last updated on 25 Jun 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc