Просмотр исходного кода

#4597 LinkedIn Connect: stopped working

Alex Trofimov 2 лет назад
Родитель
Сommit
bcfc46b0c1

+ 1 - 1
modules/boonex/linkedin_connect/classes/BxLinkedinConfig.php

@@ -21,7 +21,7 @@ class BxLinkedinConfig extends BxBaseModConnectConfig
     public $sPageStart;
     public $sPageHandle;
 
-    public $sScope = 'r_liteprofile r_emailaddress';
+    public $sScope = 'openid email profile';
 
     function __construct($aModule)
     {

+ 7 - 59
modules/boonex/linkedin_connect/classes/BxLinkedinModule.php

@@ -86,7 +86,7 @@ class BxLinkedinModule extends BxBaseModConnectModule
         $sExpiresAt = new \DateTime('+' . $sExpiresIn . ' seconds');
 
         // request info about profile
-        $s = bx_file_get_contents($this->_oConfig->sApiUrl . '/me?projection=(' . $this->_oConfig->sFields . ')', array(), 'get', array(
+        $s = bx_file_get_contents($this->_oConfig->sApiUrl . '/userinfo', array(), 'get', array(
             'Authorization: Bearer ' . $sAccessToken,
         ));
 
@@ -97,19 +97,7 @@ class BxLinkedinModule extends BxBaseModConnectModule
             return;
         }
 
-        // request email
-        $s = bx_file_get_contents($this->_oConfig->sApiUrl . '/emailAddress?q=members&projection=(elements*(handle~))', array(), 'get', array(
-            'Authorization: Bearer ' . $sAccessToken,
-        ));
-
-        // handle error
-        if (!$s || NULL === ($aResponseEmail = json_decode($s, true)) || !$aResponseEmail || (isset($aResponseEmail['status']) && ($aResponseEmail['status'] < 200 || $aResponseEmail['status'] > 299))) {
-            $sErrorDescription = isset($aResponseEmail['message']) ? $aResponseEmail['message'] : _t('_error occured'); 
-            $this->_oTemplate->getPage(_t('_Error'), MsgBox($sErrorDescription));
-            return;
-        }
-
-        $aRemoteProfileInfo = array_merge($aResponse, $aResponseEmail);
+        $aRemoteProfileInfo = array_merge($aResponse, ['id' => $aResponse['sub']]);
 
         if ($aRemoteProfileInfo) {
 
@@ -118,7 +106,7 @@ class BxLinkedinModule extends BxBaseModConnectModule
             
             if ($iLocalProfileId && $oProfile = BxDolProfile::getInstance($iLocalProfileId)) {
                 // user already exists
-                $this->setLogged($oProfile ->id());
+                $this->setLogged($oProfile->id());
             }             
             else {  
                 // register new user
@@ -139,55 +127,15 @@ class BxLinkedinModule extends BxBaseModConnectModule
     {
         $aProfileFields = $aProfileInfo;
 
-        $aProfileFields['name'] = $this->_getLocalizedValue($aProfileInfo['firstName']);
-        $aProfileFields['fullname'] = $this->_getLocalizedValue($aProfileInfo['firstName']) . ' ' . (isset($aProfileInfo['lastName']) ? $this->_getLocalizedValue($aProfileInfo['lastName']) : '');
-        $aProfileFields['email'] = isset($aProfileInfo['elements']) ? $this->_getEmail($aProfileInfo['elements']) : '';
-        $aProfileFields['picture'] = isset($aProfileInfo['profilePicture']) ? $this->_getImageUrl($aProfileInfo['profilePicture']) : '';
+        $aProfileFields['name'] = $aProfileInfo['name'];
+        $aProfileFields['fullname'] = $aProfileInfo['name'];
+        $aProfileFields['email'] = $aProfileInfo['email'];
+        $aProfileFields['picture'] = $aProfileInfo['picture'];
         $aProfileFields['allow_view_to'] = getParam('bx_linkedin_privacy');
 
         return $aProfileFields;
     }
 
-    protected function _getLocalizedValue($a) 
-    {
-        $sLocale = isset($a['preferredLocale']) ? $a['preferredLocale']['language'] . '_' . $a['preferredLocale']['country'] : false;
-        if (isset($a['localized']) && isset($a['localized'][$sLocale]))
-            return $a['localized'][$sLocale];
-        return false;
-    }
-
-    protected function _getEmail($a) 
-    {
-        $r = array_pop($a);
-        if (!isset($r['handle~']) || !isset($r['handle~']['emailAddress']))
-            return false;
-        return $r['handle~']['emailAddress'];
-    }
-
-    protected function _getImageUrl($a) 
-    {
-        if (!isset($a['displayImage~']))
-            return false;
-        $aBiggestImage = false;
-        foreach ($a['displayImage~']['elements'] as $r) {
-            if (empty($r['identifiers']) || !isset($r['data']) || !isset($r['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']) || !isset($r['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']))
-                continue;
-            if (!$aBiggestImage || $r['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] > $aBiggestImage['width']) {
-                foreach ($r['identifiers'] as $rr) {
-                    if ('EXTERNAL_URL' == $rr['identifierType']) {
-                        $aBiggestImage = array(
-                            'width' => $r['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'],
-                            'url' => $rr['identifier'],
-                        );
-                        break;
-                    }
-                }
-            }
-        }
-        if (!$aBiggestImage)
-            return false;
-        return $aBiggestImage['url'];
-    }
 }
 
 /** @} */