Реализован функционал получения информации об аккауте после выполнения oAuth авторизации

This commit is contained in:
ErickSkrauch
2016-08-06 16:36:24 +03:00
parent 26b37c2f6b
commit a48c1432c6
15 changed files with 147 additions and 63 deletions

View File

@@ -0,0 +1,8 @@
<?php
namespace api\components\ApiUser;
class AccessControl extends \yii\filters\AccessControl {
public $user = 'apiUser';
}

View File

@@ -10,10 +10,14 @@ use yii\web\User as YiiUserComponent;
*/
class Component extends YiiUserComponent {
public $identity = Identity::class;
public $identityClass = Identity::class;
public $enableSession = false;
public $loginUrl = null;
public function getAccessChecker() {
return new AuthChecker();
}
}

View File

@@ -5,4 +5,6 @@ return [
'/accounts/change-email/confirm-new-email' => 'accounts/change-email-confirm-new-email',
'/oauth2/v1/<action>' => 'oauth/<action>',
'/account/v1/info' => 'identity-info/index',
];

View File

@@ -1,9 +1,9 @@
<?php
namespace api\controllers;
use common\models\OauthScope;
use api\components\ApiUser\AccessControl;
use common\models\OauthScope as S;
use Yii;
use yii\filters\AccessControl;
use yii\helpers\ArrayHelper;
class IdentityInfoController extends ApiController {
@@ -16,7 +16,7 @@ class IdentityInfoController extends ApiController {
[
'actions' => ['index'],
'allow' => true,
'roles' => ['@'],
'roles' => [S::ACCOUNT_INFO],
],
],
],
@@ -28,12 +28,13 @@ class IdentityInfoController extends ApiController {
$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(OauthScope::ACCOUNT_EMAIL)) {
if (Yii::$app->apiUser->can(S::ACCOUNT_EMAIL)) {
$response['email'] = $account->email;
}