mirror of
https://github.com/elyby/accounts.git
synced 2025-01-11 14:32:12 +05:30
Fixes ACCOUNTS-5V9. Handle case when access token don't have associated account
This commit is contained in:
parent
a5f6a2d437
commit
22ef41ac7c
@ -1,4 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace api\modules\oauth\controllers;
|
namespace api\modules\oauth\controllers;
|
||||||
|
|
||||||
use api\controllers\Controller;
|
use api\controllers\Controller;
|
||||||
@ -19,11 +21,23 @@ class IdentityController extends Controller {
|
|||||||
'actions' => ['index'],
|
'actions' => ['index'],
|
||||||
'allow' => true,
|
'allow' => true,
|
||||||
'roles' => [P::OBTAIN_ACCOUNT_INFO],
|
'roles' => [P::OBTAIN_ACCOUNT_INFO],
|
||||||
'roleParams' => function() {
|
'roleParams' => function(): array {
|
||||||
/** @noinspection NullPointerExceptionInspection */
|
/** @var \api\components\User\IdentityInterface $identity */
|
||||||
return [
|
$identity = Yii::$app->user->getIdentity();
|
||||||
'accountId' => Yii::$app->user->getIdentity()->getAccount()->id,
|
$account = $identity->getAccount();
|
||||||
];
|
if ($account === null) {
|
||||||
|
Yii::$app->sentry->captureMessage('Unexpected lack of account', [
|
||||||
|
'identityType' => get_class($identity),
|
||||||
|
'userId' => $identity->getId(),
|
||||||
|
'assignedPermissions' => $identity->getAssignedPermissions(),
|
||||||
|
], [
|
||||||
|
'level' => 'warning',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return ['accountId' => 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['accountId' => $account->id];
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user