From 22ef41ac7c055f3f6f113d9503af85105dab8367 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 2 Dec 2019 21:14:40 +0300 Subject: [PATCH] Fixes ACCOUNTS-5V9. Handle case when access token don't have associated account --- .../oauth/controllers/IdentityController.php | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/api/modules/oauth/controllers/IdentityController.php b/api/modules/oauth/controllers/IdentityController.php index 034e8c5..57e5281 100644 --- a/api/modules/oauth/controllers/IdentityController.php +++ b/api/modules/oauth/controllers/IdentityController.php @@ -1,4 +1,6 @@ ['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]; }, ], ],