Skip to content

Commit

Permalink
Merge pull request #7 from vippsas/publication-1.2.3
Browse files Browse the repository at this point in the history
VIPPS-288: Add sub validation for userInfo
  • Loading branch information
ed007m authored Mar 4, 2020
2 parents fe2dc2f + c058d13 commit a19dc63
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Gateway/Command/UserInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Vipps\Login\Api\Data\UserInfoInterface;
use Vipps\Login\Api\Data\UserInfoInterfaceFactory;
use Vipps\Login\Api\ApiEndpointsInterface;
use Vipps\Login\Model\TokenProviderInterface;

/**
* Class UserInfoCommand
Expand All @@ -51,6 +52,11 @@ class UserInfoCommand
* @var ApiEndpointsInterface
*/
private $apiEndpoints;

/**
* @var TokenProviderInterface
*/
private $tokenPayloadProvider;

/**
* @var array
Expand All @@ -64,17 +70,20 @@ class UserInfoCommand
* @param ClientFactory $httpClientFactory
* @param UserInfoInterfaceFactory $userInfoFactory
* @param ApiEndpointsInterface $apiEndpoints
* @param TokenProviderInterface $tokenPayloadProvider
*/
public function __construct(
SerializerInterface $serializer,
ClientFactory $httpClientFactory,
UserInfoInterfaceFactory $userInfoFactory,
ApiEndpointsInterface $apiEndpoints
ApiEndpointsInterface $apiEndpoints,
TokenProviderInterface $tokenPayloadProvider
) {
$this->serializer = $serializer;
$this->httpClientFactory = $httpClientFactory;
$this->userInfoFactory = $userInfoFactory;
$this->apiEndpoints = $apiEndpoints;
$this->tokenPayloadProvider = $tokenPayloadProvider;
}

/**
Expand All @@ -99,6 +108,10 @@ public function execute($accessToken)
$body = $this->serializer->unserialize($httpClient->getBody());

if (200 <= $status && 300 > $status) {
$tokenPayload = $this->tokenPayloadProvider->get();
if (empty($body['sub']) || empty($tokenPayload['sub']) || $body['sub'] !== $tokenPayload['sub']) {
throw new LocalizedException(__('An error occurred trying to fetch user info'));
}
$this->cache[$accessToken] = $this->userInfoFactory->create(['data' => $body]);
return $this->cache[$accessToken];
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"psr/log": "~1.0"
},
"type": "magento2-module",
"version": "1.2.2",
"version": "1.2.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
6 changes: 6 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,10 @@
</arguments>
</type>

<type name="Vipps\Login\Gateway\Command\UserInfoCommand">
<arguments>
<argument name="tokenPayloadProvider" xsi:type="object">Vipps\Login\Model\TokenPayloadProvider</argument>
</arguments>
</type>

</config>

0 comments on commit a19dc63

Please sign in to comment.