validateAuthorization example

 Context::createDefaultContext());

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

        $bearerTokenValidator = new BearerTokenValidator(
            $mockDecoratedValidator,
            $connection,
            $this->getContainer()->get('shopware.jwt_config')
        );

        $bearerTokenValidator->validateAuthorization($request);
    }
}
private readonly AuthorizationValidatorInterface $decorated,
        private readonly Connection $connection,
        private readonly Configuration $configuration
    ) {
    }

    /** * @return ServerRequestInterface */
    public function validateAuthorization(ServerRequestInterface $request)
    {
        $request = $this->decorated->validateAuthorization($request);

        $header = $request->getHeader('authorization');

        $jwt = trim(preg_replace('/^(?:\s+)?Bearer\s/', '', $header[0]) ?? '');

        /** @var UnencryptedToken $token */
        $token = $this->configuration->parser()->parse($jwt);

        if ($userId = $request->getAttribute(PlatformRequest::ATTRIBUTE_OAUTH_USER_ID)) {
            $this->validateAccessTokenIssuedAt($token->claims()->get('iat', 0)$userId);
        }

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