-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enh: Configuration Settings #3
base: master
Are you sure you want to change the base?
Conversation
Seems like it still throws |
This error only happens for guest when the login modal is activated it seems. |
Currently still unable to fix this issue, not sure why it's showing up other than |
[So after fixing some of the issues it seems that
From what I'm getting it seems that |
@luke- from looking at this deeper, it's not possible to implement it in this way, I can implement it through |
@yurabakhtin could you look over this to see if I made any errors within the code? At the moment I'm completely stumped. 🤔 |
@ArchBlood If you tell about this error:
then please try to update the code |
Using
I've changed the public function loadBySettings()
{
if ($this->settingsManager !== null) {
$this->enabled = (bool)$this->settingsManager->get('enabled');
$this->url = ($this->settingsManager->get('url') ?? '');
$this->sharedKey = $this->settingsManager->getSerialized('sharedKey') ?? [];
$this->supportedAlgorithms = ($this->settingsManager->get('supportedAlgorithms') ?? []);
$this->idAttribute = ($this->settingsManager->get('idAttribute') ?? '');
$this->leeway = $this->settingsManager->get('leeway') ?? 0;
$this->allowedIPs = $this->settingsManager->get('allowedIPs') ?? [];
$this->autoLogin = (bool)$this->settingsManager->get('autoLogin');
}
} But the following error then happens for me;
|
@ArchBlood I think you should either define the property |
Seems like neither of these options work correctly either, I set like this and the login page is now viewable, but I'm not sure this is the correct way of doing this; if (!isset(Yii::$app->authClientCollection)) {
$jwtAuth = Yii::$app->authClientCollection->getClient('jwt');
if ($jwtAuth->checkIPAccess()) {
if ($jwtAuth->autoLogin && $event->action->id === 'login' && empty(Yii::$app->request->get('noJwt'))) {
if ($event->isValid) {
$event->isValid = false;
return $jwtAuth->redirectToBroker();
}
}
} else {
// Not allowed, remove authClient
Yii::$app->authClientCollection->removeClient('jwt');
}
} |
@ArchBlood I didn't run/test your code but for me it looks incorrectly when you do Why don't you use the condition as I suggested Really I think you should use instead of old code:
new code like:
or:
|
Because these throw the following error, using the current code or yii\base\ErrorException: Undefined property: humhub\components\Application::$authClientCollection in /home/USER/public_html/protected/modules/jwt-sso/Module.php:68
Stack trace:
#0 /home/USER/public_html/protected/modules/jwt-sso/Module.php(68): yii\base\ErrorHandler->handleError()
#1 [internal function]: humhub\modules\sso\jwt\Module::onAuthClientCollectionInit()
#2 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Event.php(312): call_user_func()
#3 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger()
#4 /home/USER/public_html/protected/humhub/modules/user/authclient/Collection.php(48): yii\base\Component->trigger()
#5 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Component.php(180): humhub\modules\user\authclient\Collection->setClients()
#6 /home/USER/public_html/protected/vendor/yiisoft/yii2/BaseYii.php(558): yii\base\Component->__set()
#7 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\BaseYii::configure()
#8 [internal function]: yii\base\BaseObject->__construct()
#9 /home/USER/public_html/protected/vendor/yiisoft/yii2/di/Container.php(419): ReflectionClass->newInstanceArgs()
#10 /home/USER/public_html/protected/vendor/yiisoft/yii2/di/Container.php(170): yii\di\Container->build()
#11 /home/USER/public_html/protected/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get()
#12 /home/USER/public_html/protected/vendor/yiisoft/yii2/di/ServiceLocator.php(137): yii\BaseYii::createObject()
#13 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Module.php(766): yii\di\ServiceLocator->get()
#14 /home/USER/public_html/protected/vendor/yiisoft/yii2/di/ServiceLocator.php(74): yii\base\Module->get()
#15 /home/USER/public_html/protected/modules/jwt-sso/Module.php(68): yii\di\ServiceLocator->__get()
#16 [internal function]: humhub\modules\sso\jwt\Module::onAuthClientCollectionInit()
#17 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Event.php(312): call_user_func()
#18 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger()
#19 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Controller.php(297): yii\base\Component->trigger()
#20 /home/USER/public_html/protected/vendor/yiisoft/yii2/web/Controller.php(219): yii\base\Controller->beforeAction()
#21 /home/USER/public_html/protected/humhub/components/Controller.php(210): yii\web\Controller->beforeAction()
#22 /home/USER/public_html/protected/humhub/modules/user/controllers/AuthController.php(94): humhub\components\Controller->beforeAction()
#23 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Controller.php(176): humhub\modules\user\controllers\AuthController->beforeAction()
#24 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#25 /home/USER/public_html/protected/vendor/yiisoft/yii2/web/Application.php(103): yii\base\Module->runAction()
#26 /home/USER/public_html/protected/vendor/yiisoft/yii2/base/Application.php(384): yii\web\Application->handleRequest()
#27 /home/USER/public_html/index.php(25): yii\base\Application->run()
#28 {main} |
@ArchBlood You write here |
I can switch it to that, but the error will continue to happen, should I apply error handling as well? |
After testing the following now works, but still throws public static function onAuthClientCollectionInit($event)
{
try {
if (!Yii::$app->user->isGuest) {
return;
}
/** @var Collection $authClientCollection */
$authClientCollection = $event->sender;
$config = Configuration::getInstance();
if (!empty($config->enabled)) {
$authClientCollection->setClient('jwt', [
'class' => authclient\JWT::class,
'url' => $config->url,
'sharedKey' => $config->sharedKey,
'supportedAlgorithms' => $config->supportedAlgorithms,
'idAttribute' => $config->idAttribute,
'leeway' => $config->leeway,
'allowedIPs' => $config->allowedIPs
]);
}
if (isset(Yii::$app->authClientCollection) && Yii::$app->authClientCollection->hasClient('jwt')) {
$jwtAuth = Yii::$app->authClientCollection->getClient('jwt');
if ($jwtAuth->checkIPAccess()) {
if ($jwtAuth->autoLogin && $event->action->id === 'login' && empty(Yii::$app->request->get('noJwt'))) {
if ($event->isValid) {
$event->isValid = false;
return $jwtAuth->redirectToBroker();
}
}
} else {
Yii::$app->authClientCollection->removeClient('jwt');
}
}
} catch (\Exception $e) {
// Log or handle the exception as needed
Yii::error('Error occurred: ' . $e->getMessage());
}
} |
@ArchBlood Maybe you should compare the if (!($event->sender instanceof Collection)) {
return;
} because I see the module config calls the method [Collection::class, Collection::EVENT_AFTER_CLIENTS_SET, ['humhub\modules\sso\jwt\Module', 'onAuthClientCollectionInit']],
[AuthController::class, AuthController::EVENT_BEFORE_ACTION, ['humhub\modules\sso\jwt\Module', 'onAuthClientCollectionInit']], I guess the event I just see you added the first config line for [Collection::class, Collection::EVENT_AFTER_CLIENTS_SET, ['humhub\modules\sso\jwt\Events', 'onCollectionAfterClientsSet']],
[AuthController::class, AuthController::EVENT_BEFORE_ACTION, ['humhub\modules\sso\jwt\Events', 'onAuthControllerBeforeAction']], then you should move the code(or part of the code) from Thanks. |
Yes, you are correct, but in all honesty the whole |
Now no errors happen at all! 😄 |
All that's needed now is live testing, which I can't current do as I have no JWT instances setup. |
If anyone can run some tests for this it would be nice, otherwise I believe that everything looks to be working as intended. 🤔 |
I've updated both the JWT |
Resolves: #2