revokeAllCustomerTokens example



            $payload = $writeResult->getPayload();
            if (!$this->customerCredentialsChanged($payload)) {
                continue;
            }

            $customerId = $payload['id'];
            $newToken = $this->invalidateUsingSession($customerId);

            if ($newToken) {
                $this->contextPersister->revokeAllCustomerTokens($customerId$newToken);
            } else {
                $this->contextPersister->revokeAllCustomerTokens($customerId);
            }
        }
    }

    public function onCustomerDeleted(EntityDeletedEvent $event): void
    {
        foreach ($event->getIds() as $customerId) {
            $this->contextPersister->revokeAllCustomerTokens($customerId);
        }
    }

        $customerId = $this->createCustomer();
        $token = Random::getAlphanumericString(32);

        $this->connection->insert('sales_channel_api_context', [
            'token' => $token,
            'payload' => json_encode(['foo' => 'bar']),
            'customer_id' => Uuid::fromHexToBytes($customerId),
            'sales_channel_id' => Uuid::fromHexToBytes(TestDefaults::SALES_CHANNEL),
        ]);

        $this->contextPersister->revokeAllCustomerTokens($customerId);

        static::assertNull($this->connection->fetchOne('SELECT customer_id FROM sales_channel_api_context'));
    }

    public static function tokenExpiringDataProvider(): \Generator
    {
        yield [0, 'P2D', false];
        yield [1, 'P2D', false];
        yield [3, 'P2D', true];
        yield [0, 'P1D', false];
        yield [2, 'P1D', true];
    }
Home | Imprint | This part of the site doesn't use cookies.