From c0081ac31bf27faba49780f0b9735185aac2c5c7 Mon Sep 17 00:00:00 2001 From: Calvin Froedge Date: Sun, 18 Oct 2015 17:57:49 -0400 Subject: [PATCH 1/2] Allow collection of email and other profile details from LinkedIn during identity retrieval --- linkedin_server.js | 31 +++++++++++++++++++++++-------- package.js | 4 ++-- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/linkedin_server.js b/linkedin_server.js index ff3fd70..d4723b7 100644 --- a/linkedin_server.js +++ b/linkedin_server.js @@ -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']; + +// 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; @@ -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) { diff --git a/package.js b/package.js index 6d7674b..0ecdef6 100644 --- a/package.js +++ b/package.js @@ -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' }); @@ -22,4 +22,4 @@ Package.onUse(function (api) { ], 'web'); api.export(['LinkedIn', 'Linkedin'], both); -}); \ No newline at end of file +}); From 0d7ac1b3eb1c00bb81bf34b89d6d3cefccdfa89a Mon Sep 17 00:00:00 2001 From: Calvin Froedge Date: Mon, 19 Oct 2015 08:33:11 -0400 Subject: [PATCH 2/2] Add siteStandardProfileRequest to standard query fields --- linkedin_server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linkedin_server.js b/linkedin_server.js index d4723b7..14ef4d6 100644 --- a/linkedin_server.js +++ b/linkedin_server.js @@ -8,7 +8,7 @@ LinkedIn.config = { }; // These fields are requested by default and added to the user's profile -var whiteListed = ['firstName', 'headline', 'lastName']; +var whiteListed = ['firstName', 'headline', 'lastName', 'siteStandardProfileRequest']; // You can use LinkedIn.config to add extra fields var getFields = function(){