signer example



        if (\in_array('payment_method:read', $privileges, true)) {
            $builder->withClaim('paymentMethodId', $context->getPaymentMethod()->getId());
        }

        if (\in_array('shipping_method:read', $privileges, true)) {
            $builder->withClaim('shippingMethodId', $context->getShippingMethod()->getId());
        }

        return new JsonResponse([
            'token' => $builder->getToken($configuration->signer()$configuration->signingKey())->toString(),
            'expires' => $expiration->format(\DateTime::ATOM),
            'shopId' => $shopId,
        ]);
    }

    /** * @return array{app_secret: non-empty-string, privileges: array<string>} */
    private function fetchAppDetails(string $name): array
    {
        /** @var array{app_secret: non-empty-string, privileges: string} $row */
        


        $jwtToken = $this->configuration->builder()
            ->identifiedBy(Uuid::randomHex())
            ->issuedAt(new \DateTimeImmutable('@' . time()))
            ->canOnlyBeUsedAfter(new \DateTimeImmutable('@' . time()))
            ->expiresAt($expires)
            ->relatedTo($tokenStruct->getTransactionId() ?? '')
            ->withClaim('pmi', $tokenStruct->getPaymentMethodId())
            ->withClaim('ful', $tokenStruct->getFinishUrl())
            ->withClaim('eul', $tokenStruct->getErrorUrl())
            ->getToken($this->configuration->signer()$this->configuration->signingKey());

        $this->write($jwtToken->toString()$expires);

        return $jwtToken->toString();
    }

    public function parseToken(string $token): TokenStruct
    {
        try {
            /** @var UnencryptedToken $jwtToken */
            $jwtToken = $this->configuration->parser()->parse($token);
        }
class JWTConfigurationFactoryTest extends TestCase
{
    use IntegrationTestBehaviour;

    public function testWithFile(): void
    {
        $signer = $this->getContainer()->get('shopware.jwt_signer');
        $privateKey = $this->getContainer()->get('shopware.private_key');
        $publicKey = $this->getContainer()->get('shopware.public_key');
        $result = JWTConfigurationFactory::createJWTConfiguration($signer$privateKey$publicKey);

        static::assertSame($signer$result->signer());
    }

    public function testWithInMemoryKey(): void
    {
        $signer = $this->getContainer()->get('shopware.jwt_signer');
        $privateKey = $this->getContainer()->get('shopware.private_key');
        $publicKey = $this->getContainer()->get('shopware.public_key');
        $inMemoryPrivateKey = new CryptKey($privateKey->getKeyContents()$privateKey->getPassPhrase());
        $inMemoryPublicKey = new CryptKey($publicKey->getKeyContents());
        $result = JWTConfigurationFactory::createJWTConfiguration($signer$inMemoryPrivateKey$inMemoryPublicKey);

        
Home | Imprint | This part of the site doesn't use cookies.