в конфигурации приложения:
Код: Выделить всё
'user' => [
'identityClass' => 'app\models\User',
//'enableAutoLogin' => true,
'enableSession' => false,
],
Код: Выделить всё
public static function findIdentityByAccessToken($token, $type = null)
{
$headers = Yii::$app->request->headers;
if (!isset($headers['inn'], $headers['login'], $headers['password'],
$headers['ofd_api_key'])) {
throw new \yii\web\UnauthorizedHttpException('Не достаточно параметров для авторизации', 401);
}
if (!static::findOne(['access_token' => $token])) {
throw new \yii\web\UnauthorizedHttpException('Нет авторизации', 401);
}
$model = new User;
$userData = $model->findOne([
'inn' => $headers['inn'],
'login' => $headers['login']
]);
if (!$userData) {
throw new \yii\web\UnauthorizedHttpException('Нет авторизации', 401);
}
return $userData;
}