2016-08-21 04:51:39 +05:30
|
|
|
<?php
|
2019-02-21 01:28:52 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
namespace api\modules\authserver;
|
|
|
|
|
2016-08-29 04:47:45 +05:30
|
|
|
use Yii;
|
2016-08-21 04:51:39 +05:30
|
|
|
use yii\base\BootstrapInterface;
|
2016-09-07 20:26:30 +05:30
|
|
|
use yii\web\NotFoundHttpException;
|
2016-08-21 04:51:39 +05:30
|
|
|
|
|
|
|
class Module extends \yii\base\Module implements BootstrapInterface {
|
|
|
|
|
|
|
|
public $id = 'authserver';
|
|
|
|
|
|
|
|
public $defaultRoute = 'index';
|
|
|
|
|
2016-09-07 20:26:30 +05:30
|
|
|
public function beforeAction($action) {
|
|
|
|
if (!parent::beforeAction($action)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->checkHost();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
/**
|
2019-02-21 01:28:52 +05:30
|
|
|
* @param \yii\base\Application $app
|
2016-08-21 04:51:39 +05:30
|
|
|
*/
|
|
|
|
public function bootstrap($app) {
|
2019-02-21 01:28:52 +05:30
|
|
|
$legacyHost = $app->params['authserverHost'];
|
2016-08-21 04:51:39 +05:30
|
|
|
$app->getUrlManager()->addRules([
|
2019-02-21 01:28:52 +05:30
|
|
|
"//{$legacyHost}/authserver/auth/<action>" => "{$this->id}/authentication/<action>",
|
2016-08-21 04:51:39 +05:30
|
|
|
], false);
|
|
|
|
}
|
|
|
|
|
2016-08-29 04:47:45 +05:30
|
|
|
public static function info($message) {
|
|
|
|
Yii::info($message, 'legacy-authserver');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function error($message) {
|
|
|
|
Yii::info($message, 'legacy-authserver');
|
|
|
|
}
|
|
|
|
|
2016-09-07 20:26:30 +05:30
|
|
|
/**
|
|
|
|
* Поскольку это legacy метод и документации в новой среде для него не будет,
|
|
|
|
* нет смысла выставлять на показ внутренние url, так что ограничиваем доступ
|
|
|
|
* только для заходов по старому домену
|
|
|
|
*
|
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
|
|
|
protected function checkHost() {
|
2019-02-21 01:28:52 +05:30
|
|
|
if (parse_url(Yii::$app->request->getHostInfo(), PHP_URL_HOST) !== Yii::$app->params['authserverHost']) {
|
2016-09-07 20:26:30 +05:30
|
|
|
throw new NotFoundHttpException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
}
|