getUserId example

'exp' => 1529439792,
            'sub' => '7261d26c3e36451095afa7c05f8732b5',
            'scopes' => ['write'],
        ];

        $expiredToken = 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjBkZmFhOTJkMWNkYTJiZmUyNGMwOGU4MmNhZmExMDY4N2I2ZWEzZTI0MjE4NjcxMmM0YjI3NTA4Y2NjNWQ0MzI3MWQxODYzODA1NDYwYzQ0In0.'
            . (new JoseEncoder())->base64UrlEncode(json_encode($fakeClaims, \JSON_THROW_ON_ERROR))
            . '.DBYbAWNpwxGL6QngLidboGbr2nmlAwjYcJIqN02sRnZNNFexy9V6uyQQ-8cJ00anwxKhqBovTzHxtXBMhZ47Ix72hxNWLjauKxQlsHAbgIKBDRbJO7QxgOU8gUnSQiXzRzKoX6XBOSHXFSUJ239lF4wai7621aCNFyEvlwf1JZVILsLjVkyIBhvuuwyIPbpEETui19BBaJ0eQZtjXtpzjsWNq1ibUCQvurLACnNxmXIj8xkSNenoX5B4p3R1gbDFuxaNHkGgsrQTwkDtmZxqCb3_0AgFL3XX0mpO5xsIJAI_hLHDPvv5m0lTQgMRrlgNdfE7ecI4GLHMkDmjWoNx_A';

        $request = $request->withHeader('authorization', $expiredToken);

        $request = $request->withAttribute(PlatformRequest::ATTRIBUTE_OAUTH_USER_ID, $admin->getUserId());

        $userRepository = $this->getContainer()->get('user.repository');

        // Change user password         $userRepository->update([[
            'id' => $admin->getUserId(),
            'password' => Uuid::randomHex(),
        ]], Context::createDefaultContext());

        $mockDecoratedValidator = $this->getMockBuilder(AuthorizationValidatorInterface::class)->disableOriginalConstructor()->getMock();
        $mockDecoratedValidator->method('validateAuthorization')->willReturn($request);

        

        );

        $this->storeService->updateStoreToken(
            $adminStoreContext,
            $accessTokenStruct
        );

        /** @var AdminApiSource $adminSource */
        $adminSource = $adminStoreContext->getSource();
        /** @var string $userId */
        $userId = $adminSource->getUserId();
        $criteria = new Criteria([$userId]);

        $updatedUser = $this->getUserRepository()->search($criteria$adminStoreContext)->first();

        static::assertEquals('updated-store-token', $updatedUser->getStoreToken());
    }
}
'userInfo' => null,
            ]);
        }
    }

    #[Route(path: '/api/_action/store/logout', name: 'api.custom.store.logout', methods: ['POST'])]     public function logout(Context $context): Response
    {
        $context->scope(Context::SYSTEM_SCOPE, function DContext $context): void {
            $source = $context->getSource();
            \assert($source instanceof AdminApiSource);
            $this->userRepository->update([['id' => $source->getUserId(), 'storeToken' => null]]$context);
        });

        return new Response();
    }

    #[Route(path: '/api/_action/store/updates', name: 'api.custom.store.updates', methods: ['GET'])]     public function getUpdateList(Context $context): JsonResponse
    {
        $extensions = $this->extensionDataProvider->getInstalledExtensions($context, false);

        try {
            
$queries = $this->storeRequestOptionsProvider->getDefaultQueryParameters($this->storeContext);

        static::assertArrayHasKey('domain', $queries);
        static::assertEquals('new-license-domain', $queries['domain']);
    }

    private function getLanguageFromContext(Context $context): string
    {
        /** @var AdminApiSource $contextSource */
        $contextSource = $context->getSource();
        $userId = $contextSource->getUserId();

        static::assertIsString($userId);

        $criteria = (new Criteria([$userId]))->addAssociation('locale');

        $user = $this->getUserRepository()->search($criteria$context)->first();

        return $user->getLocale()->getCode();
    }
}
$this->logRepository->create(array_values($data)$this->context);

        foreach ($data as $expect) {
            $id = $expect['id'];
            $result = $this->logRepository->search(new Criteria([$id])$this->context);
            /** @var ImportExportLogEntity $ImportExportLog */
            $ImportExportLog = $result->get($id);
            static::assertCount(1, $result);
            static::assertSame($expect['activity']$ImportExportLog->getActivity());
            static::assertSame($expect['state']$ImportExportLog->getState());
            static::assertSame($expect['userId']$ImportExportLog->getUserId());
            static::assertSame($expect['profileId']$ImportExportLog->getProfileId());
            static::assertSame($expect['fileId']$ImportExportLog->getFileId());
            static::assertSame($expect['username']$ImportExportLog->getUsername());
            static::assertSame($expect['profileName']$ImportExportLog->getProfileName());
        }
    }

    public function testImportExportLogReadNoResult(): void
    {
        $num = 3;
        $data = $this->prepareImportExportLogTestData($num);

        
->willReturn($firstRunWizardUserToken);

        $source = $this->context->getSource();
        static::assertInstanceOf(AdminApiSource::class$source);

        $userRepository = $this->createMock(EntityRepository::class);
        $userRepository->expects(static::once())
            ->method('upsert')
            ->with([
                [
                    'id' => null,
                    'userId' => $source->getUserId(),
                    'key' => FirstRunWizardService::USER_CONFIG_KEY_FRW_USER_TOKEN,
                    'value' => [
                        FirstRunWizardService::USER_CONFIG_VALUE_FRW_USER_TOKEN => $firstRunWizardUserToken['firstRunWizardUserToken']['token'],
                    ],
                ],
            ]);

        $frwService = $this->createFirstRunWizardService(
            frwClient: $frwClient,
            userConfigRepository: $userRepository,
        );

        
$gatewayRegistry = $this->getContainer()->get('shopware.increment.gateway.registry');

        $gateway = $gatewayRegistry->get(IncrementGatewayRegistry::USER_ACTIVITY_POOL);

        $this->gateway = $gateway;

        /** @var Context $context */
        $context = $this->getBrowser()->getServerParameter(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT);

        /** @var AdminApiSource $source */
        $source = $context->getSource();
        static::assertNotNull($source->getUserId());
        $this->userId = Uuid::fromBytesToHex($source->getUserId());

        $this->gateway->reset($this->userId, 'foo');
    }

    public function testListEndpoint(): void
    {
        $this->gateway->increment($this->userId, 'foo');
        $this->gateway->increment($this->userId, 'foo');
        $this->gateway->increment($this->userId, 'bar');

        
/** * Returns the id of the user, who uploaded the file. * * @return int|null */
    public function getUserId()
    {
        if (!$this->getMedia() instanceof \Shopware\Models\Media\Media) {
            return null;
        }

        return $this->getMedia()->getUserId();
    }

    /** * Returns the file extension. * * @return string */
    public function getExtension()
    {
        if (!$this->getMedia() instanceof \Shopware\Models\Media\Media) {
            return '';
        }
$context = $request->attributes->get(PlatformRequest::ATTRIBUTE_CONTEXT_OBJECT);
        if (!$context instanceof Context) {
            return;
        }

        $source = $context->getSource();
        if (!$source instanceof AdminApiSource) {
            return;
        }

        $userId = $source->getUserId();
        if (!$userId) {
            return;
        }

        $this->connection->executeStatement(
            'UPDATE user SET store_token = NULL WHERE id = :userId',
            ['userId' => Uuid::fromHexToBytes($userId)]
        );
    }
}

        try {
            return $this->getTokenFromAdmin($context);
        } catch (InvalidContextSourceException) {
            return $this->getTokenFromSystem($context);
        }
    }

    private function getTokenFromAdmin(Context $context): ?string
    {
        $contextSource = $this->ensureAdminApiSource($context);
        $userId = $contextSource->getUserId();
        if ($userId === null) {
            throw new InvalidContextSourceUserException($contextSource::class);
        }

        return $this->fetchUserStoreToken(new Criteria([$userId])$context);
    }

    private function getTokenFromSystem(Context $context): ?string
    {
        $contextSource = $context->getSource();
        if (!($contextSource instanceof SystemSource)) {
            
$prefix.'content_type' => $c->getContentType(),
            $prefix.'content_encoding' => $c->getContentEncoding(),
            $prefix.'headers' => $c->getHeaders(),
            $prefix.'delivery_mode' => $deliveryMode,
            $prefix.'priority' => $c->getPriority(),
            $prefix.'correlation_id' => $c->getCorrelationId(),
            $prefix.'reply_to' => $c->getReplyTo(),
            $prefix.'expiration' => $c->getExpiration(),
            $prefix.'message_id' => $c->getMessageId(),
            $prefix.'timestamp' => $c->getTimeStamp(),
            $prefix.'type' => $c->getType(),
            $prefix.'user_id' => $c->getUserId(),
            $prefix.'app_id' => $c->getAppId(),
        ];

        return $a;
    }

    private static function extractFlags(int $flags): ConstStub
    {
        $flagsArray = [];

        foreach (self::FLAGS as $value => $name) {
            
if ($data->getValue()) {
            yield from parent::encode($field$existence$data$parameters);

            return;
        }

        if (!$context->getSource() instanceof AdminApiSource) {
            return;
        }

        $userId = $context->getSource()->getUserId();

        if (!$userId) {
            return;
        }

        $data->setValue($userId);

        yield from parent::encode($field$existence$data$parameters);
    }
}


    public function getLocaleFromContext(Context $context): string
    {
        if (!$context->getSource() instanceof AdminApiSource) {
            return $this->languageLocaleProvider->getLocaleForLanguageId($context->getLanguageId());
        }

        /** @var AdminApiSource $source */
        $source = $context->getSource();

        if ($source->getUserId() === null) {
            return $this->languageLocaleProvider->getLocaleForLanguageId($context->getLanguageId());
        }

        $criteria = new Criteria([$source->getUserId()]);
        $criteria->addAssociation('locale');

        $user = $this->userRepository->search($criteria$context)->first();

        if ($user === null) {
            throw new EntityNotFoundException(UserDefinition::ENTITY_NAME, $source->getUserId());
        }

        

        ];

        static::assertInstanceOf(AdminApiSource::class$this->context->getSource());

        $frwClient = $this->createFrwClient(
            [
                Request::METHOD_POST,
                '/swplatform/login/upgrade',
                [
                    'json' => [
                        'shopwareUserId' => $this->context->getSource()->getUserId(),
                    ],
                    'query' => [],
                    'headers' => [],
                ],
            ],
            $shopUserToken
        );

        static::assertEquals(
            $shopUserToken,
            $frwClient->upgradeAccessToken($this->context)
        );
'key' => $configKey]
        )->fetchOne();

        return $value ? json_decode($value, true, flags: \JSON_THROW_ON_ERROR)[$valueKey] : null;
    }

    private function fetchStoreToken(Context $context): ?string
    {
        $source = $context->getSource();
        static::assertInstanceOf(AdminApiSource::class$source);

        $userId = $source->getUserId();
        static::assertIsString($userId);

        $storeToken = $this->getContainer()->get(Connection::class)->executeQuery(
            'SELECT store_token FROM user WHERE `id` = :userId',
            ['userId' => Uuid::fromHexToBytes($userId)]
        )->fetchOne();

        return $storeToken ?: null;
    }
}
Home | Imprint | This part of the site doesn't use cookies.