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

node-linkedin-headless-oauth

v2.0.2

Published

Access node-linkedin API without any browser interaction.

Downloads

3

Readme

node-linkedin-headless-oauth

Handle the node-linkedin package's authentication procedures without ever having to interact with a browser.


Overview

There are two parts to authenticating with OAuth 2.0 in the Linked API:

  1. Requesting an Authorization Code
  2. Exchanging the Authorization Code for an Access Token

Normally, for step 1, node-linkedin requires the client to start the server, open a browser, and navigate to a specific url (e.g., http://localhost:5000/oauth/linkedin) to authorize the app to connect to the LinkedIn API.

Thanks to this library, the client no longer needs to do so; instead, she can now programmatically obtain the authorization code. As of v2.0.0, this library also handles step 2; it programmatically obtains an authorization code and trades said code for an access token. Afterwards, it utilizes the access token to initiate a connection the LinkedIn API (a.k.a, LinkedIn.init('access_token')) and exposes said connection to the user. All in all, this library handles authenticating to the LinkedIn API via OAuth 2.0, so that consumers only have to provide the necessary credentials before using the API.


Specifics

WITHOUT THIS LIBRARY

var app = require('express')();

var linkedin = null;

var linkedinAuthMgr = require('node-linkedin')('app-id','secret','callbackUrl');

// User needs to open browser and navigate to this
// URL, where she will enter email & password to
// authorize this app to connect to LinkedIn API.
app.get('/oauth/linkedin', function(req, res) {
	linkedinAuthMgr.auth.authorize(res, 
		['r_basicprofile']);
});

app.get('/oauth/linkedin/callback', function(req, res) {
	linkedinAuthMgr.auth.getAccessToken(
		res, req.query.code, req.query.state, 
		function(err, results) {
			if(err) { throw err; }
			linkedin = linkedinAuthMgr.init(
				result.access_token);
			return res.redirect('/');	
		}
	);
});

app.get('/', function(req, res) {
	linkedin.people.me(function(err, $in) {
		console.log($in);
	});
});

WITH THIS LIBRARY

var app = require('express')();

// This library
var linkedinAuthUtils = require('node-linkedin-headless-oauth');
linkedinAuthUtils.run('config.json', app, function(req, res) {
	res.redirect('/');
});
app.get('/', function(req, res) {
	linkedinAuthUtils.linkedin.people.me(function(err, $in) {
		console.log($in);
	});
});

var port = process.env.PORT || 5000;
app.listen(port, function() {
	console.log('Node app is running on port', port);
});

Usage

linkedinAuthUtils.run(pathToJsonConfigFile, expressJSAppObject, responseHandlerFunction);

pathToJsonConfigFile Path to JSON configuration file. File should be structured as follows: { "apiKey": "", "secret": "", "email": "", "password": "", "callbackUrl": "", "scope": [""] }

expressJSAppObject The ExpressJS app that is connecting to the LinkedIn API and is using this library to authenticate into LinkedIn via OAuth 2.0 Example: "require('express')()"

responseHandlerFunction Function to execute after receiving the access token and initializing the connection to the LinkedIn API (stored in linkedinAuthUtils.linkedin). Example: function(req, res) { res.redirect('/'); }

linkedinAuthUtils.linkedin Object that serves as a connection to LinkedIn API; use to make API calls. Check node-linkedin: 0.5.4 for usage information.


Dependencies

phantomjs-prebuilt: 2.1.12 node-horseman: 3.1.1 node-linkedin: 0.5.4 jsonfile: 2.3.1