mirror of
https://github.com/elyby/accounts.git
synced 2024-11-06 08:11:24 +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
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\modules\oauth\controllers;
|
||||
|
||||
use api\controllers\Controller;
|
||||
@ -19,11 +21,23 @@ class IdentityController extends Controller {
|
||||
'actions' => ['index'],
|
||||
'allow' => true,
|
||||
'roles' => [P::OBTAIN_ACCOUNT_INFO],
|
||||
'roleParams' => function() {
|
||||
/** @noinspection NullPointerExceptionInspection */
|
||||
return [
|
||||
'accountId' => Yii::$app->user->getIdentity()->getAccount()->id,
|
||||
];
|
||||
'roleParams' => function(): array {
|
||||
/** @var \api\components\User\IdentityInterface $identity */
|
||||
$identity = Yii::$app->user->getIdentity();
|
||||
$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…
Reference in New Issue
Block a user