mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Попытка реализовать отдельный компонент для oAuth авторизации в свой же API. Не тестировал, не проверял работу, просто пушнул, чтобы потом продолжить в дргуом месте.
This commit is contained in:
43
api/controllers/IdentityInfoController.php
Normal file
43
api/controllers/IdentityInfoController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace api\controllers;
|
||||
|
||||
use common\models\OauthScope;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
class IdentityInfoController extends ApiController {
|
||||
|
||||
public function behaviors() {
|
||||
return ArrayHelper::merge(parent::behaviors(), [
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['index'],
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionIndex() {
|
||||
$account = Yii::$app->apiUser->getIdentity()->getAccount();
|
||||
$response = [
|
||||
'id' => $account->id,
|
||||
'uuid' => $account->uuid,
|
||||
'registeredAt' => $account->created_at,
|
||||
'profileLink' => $account->getProfileLink(),
|
||||
'preferredLanguage' => $account->lang,
|
||||
];
|
||||
|
||||
if (Yii::$app->apiUser->can(OauthScope::ACCOUNT_EMAIL)) {
|
||||
$response['email'] = $account->email;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user