mirror of
https://github.com/e107inc/e107.git
synced 2025-07-15 12:06:19 +02:00
Suppress uncaught Hybridauth exceptions in e_user_provider
And add a check for those exceptions in `social_ui::generateSocialLoginSection()` Fixes: #4192
This commit is contained in:
@ -1171,6 +1171,8 @@ class e_user_provider
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
$this->respawnHybridauth();
|
$this->respawnHybridauth();
|
||||||
$this->setProvider($provider);
|
$this->setProvider($provider);
|
||||||
|
|
||||||
@ -1180,7 +1182,19 @@ class e_user_provider
|
|||||||
$this->adapter = $this->hybridauth->getAdapter($providerId);
|
$this->adapter = $this->hybridauth->getAdapter($providerId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (\Hybridauth\Exception\InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
if (!$suppress_exceptions) throw $e;
|
||||||
|
}
|
||||||
|
catch (\Hybridauth\Exception\UnexpectedValueException $e)
|
||||||
|
{
|
||||||
|
if (!$suppress_exceptions) throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws \Hybridauth\Exception\InvalidArgumentException
|
||||||
|
*/
|
||||||
private function respawnHybridauth()
|
private function respawnHybridauth()
|
||||||
{
|
{
|
||||||
$this->hybridauth = new Hybridauth\Hybridauth($this->_config);
|
$this->hybridauth = new Hybridauth\Hybridauth($this->_config);
|
||||||
@ -1237,9 +1251,10 @@ class e_user_provider
|
|||||||
/**
|
/**
|
||||||
* Get the social login providers for which we have adapters
|
* Get the social login providers for which we have adapters
|
||||||
*
|
*
|
||||||
* This function is slow! Please cache the output instead of calling it multiple times.
|
* Despite this being a static method, it memoizes (caches) the slow reflection code in the {@link e107} registry
|
||||||
|
* after the first run, so subsequent calls to this method are fast.
|
||||||
*
|
*
|
||||||
* @return array String list of supported providers. Empty if Hybridauth is broken.
|
* @return string[] String list of supported providers. Empty if Hybridauth is broken.
|
||||||
*/
|
*/
|
||||||
public static function getSupportedProviders()
|
public static function getSupportedProviders()
|
||||||
{
|
{
|
||||||
|
@ -606,6 +606,19 @@ class social_ui extends e_admin_ui
|
|||||||
|
|
||||||
foreach ($provider_names as $provider_name)
|
foreach ($provider_names as $provider_name)
|
||||||
{
|
{
|
||||||
|
// Check if the current configuration for the provider is valid
|
||||||
|
try
|
||||||
|
{
|
||||||
|
new e_user_provider($provider_name, [], false);
|
||||||
|
}
|
||||||
|
catch (\Hybridauth\Exception\InvalidArgumentException $e)
|
||||||
|
{
|
||||||
|
e107::getMessage()->addError("[{$e->getCode()}] {$e->getMessage()}");
|
||||||
|
}
|
||||||
|
catch (\Hybridauth\Exception\UnexpectedValueException $ignored)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
$text .= $this->generateSocialLoginRow($provider_name, $readonly);
|
$text .= $this->generateSocialLoginRow($provider_name, $readonly);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,4 +115,32 @@ class e_user_providerTest extends \Codeception\Test\Unit
|
|||||||
$result = e_user_provider::getSupplementalFieldsOf("Vkontakte");
|
$result = e_user_provider::getSupplementalFieldsOf("Vkontakte");
|
||||||
$this->assertTrue(array_key_exists('photo_size', $result));
|
$this->assertTrue(array_key_exists('photo_size', $result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNewSuppressExceptions()
|
||||||
|
{
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
e_user_provider::class,
|
||||||
|
new e_user_provider("Facebook", ["providers" => ["Facebook", ["enabled" => true]]])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNewNoSuppressConfigurationException()
|
||||||
|
{
|
||||||
|
$this->expectException(\Hybridauth\Exception\InvalidArgumentException::class);
|
||||||
|
new e_user_provider(
|
||||||
|
"Facebook",
|
||||||
|
["providers" => ["Facebook" => ["enabled" => true]]],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNewNoSuppressDisabledException()
|
||||||
|
{
|
||||||
|
$this->expectException(\Hybridauth\Exception\UnexpectedValueException::class);
|
||||||
|
new e_user_provider(
|
||||||
|
"Facebook",
|
||||||
|
["providers" => ["Facebook" => ["enabled" => false]]],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user