registerApp example

$secretAccessKey = AccessKeyHelper::generateSecretAccessKey();
        $this->createApp($id);

        $manifest = Manifest::createFromXmlFile(__DIR__ . '/_fixtures/minimal/manifest.xml');

        $appSecret = 'dont_tell';
        $appResponseBody = $this->buildAppResponse($manifest$appSecret);

        $this->appendNewResponse(new Response(200, []$appResponseBody));
        $this->appendNewResponse(new Response(200, []));

        $this->registrator->registerApp($manifest$id$secretAccessKey, Context::createDefaultContext());

        $registrationRequest = $this->getPastRequest(0);

        $setup = $manifest->getSetup();
        static::assertNotNull($setup);

        $uriWithoutQuery = $registrationRequest->getUri()->withQuery('');
        static::assertEquals($setup->getRegistrationUrl()(string) $uriWithoutQuery);
        static::assertNotEmpty($registrationRequest->getHeaderLine('sw-version'));
        static::assertNotEmpty($registrationRequest->getHeaderLine(AuthMiddleware::SHOPWARE_USER_LANGUAGE));
        static::assertNotEmpty($registrationRequest->getHeaderLine(AuthMiddleware::SHOPWARE_CONTEXT_LANGUAGE));

        
$app = $this->loadApp($id$context);

        $this->updateCustomEntities($app->getId()$app->getPath()$manifest);

        $this->permissionPersister->updatePrivileges($manifest->getPermissions()$roleId);

        // If the app has no secret yet, but now specifies setup data we do a registration to get an app secret         // this mostly happens during install, but may happen in the update case if the app previously worked without an external server         if (!$app->getAppSecret() && $manifest->getSetup()) {
            try {
                $this->registrationService->registerApp($manifest$id$secretAccessKey$context);
            } catch (AppRegistrationException $e) {
                $this->removeAppAndRole($app$context);

                throw $e;
            }
        }

        // Refetch app to get secret after registration         $app = $this->loadApp($id$context);

        try {
            
$this->appRepository->update([
            [
                'id' => $app->getId(),
                'integration' => [
                    'id' => $app->getIntegrationId(),
                    'accessKey' => AccessKeyHelper::generateAccessKey('integration'),
                    'secretAccessKey' => $secret,
                ],
            ],
        ]$context);

        $this->registrationService->registerApp($manifest$app->getId()$secret$context);
    }

    private function getAppForManifest(Manifest $manifest, AppCollection $installedApps): ?AppEntity
    {
        $matchedApps = $installedApps->filter(static fn (AppEntity $installedApp): bool => $installedApp->getName() === $manifest->getMetadata()->getName());

        return $matchedApps->first();
    }
}
class AppRegistrationServiceTest extends TestCase
{
    public function testDoesNotRegisterAtAppServerIfManifestHasNoSetup(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../_fixtures/manifest_no_setup.xml');

        $handshakeFactory = $this->createMock(HandshakeFactory::class);
        $handshakeFactory->expects(static::never())
            ->method('create');

        $appRegistrationService = $this->createAppRegistrationService();
        $appRegistrationService->registerApp($manifest, 'id', 's3cr3t-4cc3s-k3y', Context::createDefaultContext());
    }

    public function testThrowsAppRegistrationExceptionIfStoreHandshakeFails(): void
    {
        $manifest = Manifest::createFromXmlFile(__DIR__ . '/../_fixtures/manifest.xml');

        $handshake = new StoreHandshake(
            'https://shopware.swag',
            'http://app.server/register',
            'test',
            'shop-id',
            
Home | Imprint | This part of the site doesn't use cookies.