-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from shopware/next-36521/in-app-purchases-jwt
NEXT-36521 - in app purchases JWT
- Loading branch information
Showing
42 changed files
with
1,639 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopware\App\SDK\Context\InAppPurchase; | ||
|
||
use Lcobucci\JWT\Token; | ||
use Lcobucci\JWT\UnencryptedToken; | ||
use Lcobucci\JWT\Validation\Constraint; | ||
use Lcobucci\JWT\Validation\ConstraintViolation; | ||
use Shopware\App\SDK\Shop\ShopInterface; | ||
|
||
/** | ||
* @phpstan-import-type InAppPurchaseArray from InAppPurchaseProvider | ||
*/ | ||
class HasMatchingDomain implements Constraint | ||
{ | ||
public function __construct(private readonly ShopInterface $shop) | ||
{ | ||
} | ||
|
||
public function assert(Token $token): void | ||
{ | ||
if (!$token instanceof UnencryptedToken) { | ||
throw new \Exception('Incorrect token type'); | ||
} | ||
|
||
/** @var InAppPurchaseArray $inAppPurchase */ | ||
foreach ($token->claims()->all() as $inAppPurchase) { | ||
if (!\array_key_exists('sub', $inAppPurchase)) { | ||
throw ConstraintViolation::error('Missing sub claim', $this); | ||
} | ||
|
||
$host = \parse_url($this->shop->getShopUrl(), \PHP_URL_HOST); | ||
|
||
if ($inAppPurchase['sub'] !== $host) { | ||
throw ConstraintViolation::error('Token domain invalid: ' . $inAppPurchase['sub'] . ', expected: ' . $host, $this); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.