Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions linkedin_server.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
var urlUtil = Npm.require('url');

// Use this for advanced configuration of LinkedIn integration, such as customizing what the API returns based on your application needs & requested permissions. Possible options:
//
// fields: an Array of LinkedIn fields, such as ['id','firstName','lastName','emailAddress','headline','memberUrlResources','pictureUrl','location','publicProfileUrl','siteStandardProfileRequest']
LinkedIn.config = {
fields: []
};

// These fields are requested by default and added to the user's profile
var whiteListed = ['firstName', 'headline', 'lastName', 'siteStandardProfileRequest'];

// You can use LinkedIn.config to add extra fields
var getFields = function(){
return _.uniq(whiteListed.concat(LinkedIn.config.fields || []));
}

OAuth.registerService('linkedin', 2, null, function (query) {

var response = getTokens(query);
var accessToken = response.accessToken;
var identity = getIdentity(accessToken);

var profileUrl = identity.siteStandardProfileRequest.url;
var urlParts = urlUtil.parse(profileUrl, true);
if(identity.siteStandardProfileRequest){
var profileUrl = identity.siteStandardProfileRequest.url;
var urlParts = urlUtil.parse(profileUrl, true);
}

var serviceData = {
id: urlParts.query.id || Random.id(),
id: identity.id || urlParts.query.id || Random.id(),
accessToken: OAuth.sealSecret(accessToken),
expiresAt: (+new Date) + (1000 * response.expiresIn)
};

var whiteListed = ['firstName', 'headline', 'lastName'];

// include all fields from linkedin
// include selected fields from linkedin
// https://developer.linkedin.com/documents/authentication
var fields = _.pick(identity, whiteListed);
var fields = _.pick(identity, getFields());

fields.name = identity.firstName + ' ' + identity.lastName;

Expand Down Expand Up @@ -87,7 +102,7 @@ var getTokens = function (query) {

var getIdentity = function (accessToken) {
try {
return HTTP.get('https://www.linkedin.com/v1/people/~', {
return HTTP.get('https://www.linkedin.com/v1/people/~:('+getFields().join(',')+')', {
params: { oauth2_access_token: accessToken, format: 'json'}
}).data;
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: 'jonperl:linkedin',
summary: 'LinkedIn accounts OAuth flow',
version: '1.1.0',
version: '1.1.1',
git: 'https://github.com/jperl/meteor-linkedin'
});

Expand All @@ -22,4 +22,4 @@ Package.onUse(function (api) {
], 'web');

api.export(['LinkedIn', 'Linkedin'], both);
});
});