auth0 / passport-linkedin-oauth2

Passport Strategy for LinkedIn OAuth 2.0
MIT License
119 stars 106 forks source link

Multilanguage support #16

Closed schartier closed 9 years ago

schartier commented 10 years ago

I am creating an application that requires to download user profile in multiple language.

As stated here (selecting the profile language) it is stated that you can download the different versions (lang) of the linkedin profile using the "Accept-Language" header.

I successfully selected the language profile as follow, but I need to get the profile in another language too. I did not found a way to achieve this but reproducing the logic outside the strategy or (maybe) creating 2 different LinkedInStrategy...

Anyone else think this would be a good idea to provide a way to download profiles in multiple languages all at once?

passport.use(new LinkedInStrategy({
      clientID: config.linkedin.clientID,
      clientSecret: config.linkedin.clientSecret,
      callbackURL: config.linkedin.callbackURL,
      scope: ['r_emailaddress', 'r_contactinfo', 'r_fullprofile'],
      customHeaders: {"x-li-format":"json", 'Accept-Language': config.defaultLang}
    },
    function(accessToken, refreshToken, profile, done) {
jfromaniello commented 9 years ago

Sorry for the 6 months delay!! :(

I'd rather do something along this:

var LinkedInStrategy = require('passport-linkedin-oauth2').Strategy;
var request = require('request');

function getProfile(token lang, done) {
  request.get({
   url: strategy. profileUrl, 
   headers: { 
     "x-li-format":"json", 
     "Accept-Language": lang, 
     "Authentication": "Bearer " + token
  }, done);
}

var strategy = new LinkedInStrategy({
  clientID: LINKEDIN_KEY,
  clientSecret: LINKEDIN_SECRET,
  callbackURL: "http://127.0.0.1:3000/auth/linkedin/callback",
  scope: ['r_emailaddress', 'r_basicprofile'],
  state: true
}, function(accessToken, refreshToken, profile, done) {
   getProfile(accessToken, 'es', function (err, profileES) {
     profile.langs = { 'es': profileES };
     done(null, profile);
   });
})
passport.use(strategy);