mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implementation of the backend for the OAuth2 clients management
This commit is contained in:
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\OauthAccountInfo;
|
||||
use common\rbac\Permissions as P;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class IdentityInfoController extends Controller {
|
||||
|
||||
public function behaviors(): array {
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['index'],
|
||||
'allow' => true,
|
||||
'roles' => [P::OBTAIN_ACCOUNT_INFO],
|
||||
'roleParams' => function() {
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
return [
|
||||
'accountId' => Yii::$app->user->getIdentity()->getAccount()->id,
|
||||
];
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionIndex(): array {
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
return (new OauthAccountInfo(Yii::$app->user->getIdentity()->getAccount()))->info();
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\OauthProcess;
|
||||
use common\rbac\Permissions as P;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class OauthController extends Controller {
|
||||
|
||||
public function behaviors(): array {
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
'authenticator' => [
|
||||
'only' => ['complete'],
|
||||
],
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'only' => ['complete'],
|
||||
'rules' => [
|
||||
[
|
||||
'allow' => true,
|
||||
'actions' => ['complete'],
|
||||
'roles' => [P::COMPLETE_OAUTH_FLOW],
|
||||
'roleParams' => function() {
|
||||
return [
|
||||
'accountId' => Yii::$app->user->identity->getAccount()->id,
|
||||
];
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function verbs(): array {
|
||||
return [
|
||||
'validate' => ['GET'],
|
||||
'complete' => ['POST'],
|
||||
'token' => ['POST'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionValidate(): array {
|
||||
return $this->createOauthProcess()->validate();
|
||||
}
|
||||
|
||||
public function actionComplete(): array {
|
||||
return $this->createOauthProcess()->complete();
|
||||
}
|
||||
|
||||
public function actionToken(): array {
|
||||
return $this->createOauthProcess()->getToken();
|
||||
}
|
||||
|
||||
private function createOauthProcess(): OauthProcess {
|
||||
return new OauthProcess(Yii::$app->oauth->authServer);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user