mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Попытка реализовать отдельный компонент для oAuth авторизации в свой же API. Не тестировал, не проверял работу, просто пушнул, чтобы потом продолжить в дргуом месте.
This commit is contained in:
31
api/controllers/ApiController.php
Normal file
31
api/controllers/ApiController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
|
||||
/**
|
||||
* Поведения:
|
||||
* @mixin \yii\filters\ContentNegotiator
|
||||
* @mixin \yii\filters\VerbFilter
|
||||
* @mixin HttpBearerAuth
|
||||
*/
|
||||
class ApiController extends \yii\rest\Controller {
|
||||
|
||||
public function behaviors() {
|
||||
$parentBehaviors = parent::behaviors();
|
||||
// Добавляем авторизатор для входа по Bearer токенам
|
||||
$parentBehaviors['authenticator'] = [
|
||||
'class' => HttpBearerAuth::class,
|
||||
'user' => Yii::$app->apiUser,
|
||||
];
|
||||
|
||||
// xml нам не понадобится
|
||||
unset($parentBehaviors['contentNegotiator']['formats']['application/xml']);
|
||||
// rate limiter здесь не применяется
|
||||
unset($parentBehaviors['rateLimiter']);
|
||||
|
||||
return $parentBehaviors;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user