-
Notifications
You must be signed in to change notification settings - Fork 2
/
Module.php
46 lines (40 loc) · 1.21 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2019 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\sso\jwt;
use humhub\components\Event;
use Yii;
use yii\helpers\Url;
class Module extends \humhub\components\Module
{
public $resourcesPath = 'resources';
/**
* JWT Handling on login page
*
* @param Event $event
* @return void
* @throws \yii\base\InvalidConfigException
* @since 1.1
*/
public static function onAuthClientCollectionInit($event)
{
if (!Yii::$app->user->isGuest) {
return;
}
if (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'))) {
$event->isValid = false;
return $jwtAuth->redirectToBroker();
}
} else {
// Not allowed, remove authClient
Yii::$app->authClientCollection->removeClient('jwt');
}
}
}
}