mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Объединены сущности для авторизации посредством JWT токенов и токенов, выданных через oAuth2.
Все действия, связанные с аккаунтами, теперь вызываются через url `/api/v1/accounts/<id>/<action>`. Добавлена вменяемая система разграничения прав на основе RBAC. Теперь oAuth2 токены генерируются как случайная строка в 40 символов длинной, а не UUID. Исправлен баг с неправильным временем жизни токена в ответе успешного запроса аутентификации. Теперь все unit тесты можно успешно прогнать без наличия интернета.
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\components\ApiUser\AccessControl;
|
||||
use common\models\OauthScope as S;
|
||||
use api\models\OauthAccountInfo;
|
||||
use common\rbac\Permissions as P;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class IdentityInfoController extends ApiController {
|
||||
class IdentityInfoController extends Controller {
|
||||
|
||||
public function behaviors() {
|
||||
public function behaviors(): array {
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
@@ -16,29 +17,22 @@ class IdentityInfoController extends ApiController {
|
||||
[
|
||||
'actions' => ['index'],
|
||||
'allow' => true,
|
||||
'roles' => [S::ACCOUNT_INFO],
|
||||
'roles' => [P::OBTAIN_ACCOUNT_INFO],
|
||||
'roleParams' => function() {
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
return [
|
||||
'accountId' => Yii::$app->user->getIdentity()->getAccount()->id,
|
||||
];
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionIndex() {
|
||||
$account = Yii::$app->apiUser->getIdentity()->getAccount();
|
||||
$response = [
|
||||
'id' => $account->id,
|
||||
'uuid' => $account->uuid,
|
||||
'username' => $account->username,
|
||||
'registeredAt' => $account->created_at,
|
||||
'profileLink' => $account->getProfileLink(),
|
||||
'preferredLanguage' => $account->lang,
|
||||
];
|
||||
|
||||
if (Yii::$app->apiUser->can(S::ACCOUNT_EMAIL)) {
|
||||
$response['email'] = $account->email;
|
||||
}
|
||||
|
||||
return $response;
|
||||
public function actionIndex(): array {
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
return (new OauthAccountInfo(Yii::$app->user->getIdentity()->getAccount()))->info();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user