Hier mal ein Beispiel, wie ich ein Cookie erstelle.
private function createCookie(Request $request, string $customerSessionToken, int $days = 7): Cookie
{
$cookie = Cookie::create(MoorlCustomerSession::COOKIE_TOKEN_NAME, $customerSessionToken);
$cookie->setSecureDefault($request->isSecure());
$cookie = $cookie->withExpires(time() + 60 * 60 * 24 * $days);
return $cookie->withHttpOnly();
}
Aber der State-Cookie reicht nicht! Bzw ist auch garnicht notwendig.
Hier ein Auszug, wie ein Login aussehen sollte/könnte
$contextToken = $this->accountService->loginById($customerSession->getCustomerId(), $this->salesChannelContext);
if (!$this->systemConfigService->getBool('MoorlCustomerSession.config.disableRedirect', $salesChannelId)) {
/* timeout */
$redirectTimeout = $this->systemConfigService->getInt('MoorlCustomerSession.config.redirectTimeout', $salesChannelId);
sleep($redirectTimeout);
/* get request url */
$url = $request->attributes->get(RequestTransformer::STOREFRONT_URL) . $request->attributes->get(RequestTransformer::SALES_CHANNEL_RESOLVED_URI);
/* convert to redirect response */
$redirectResponse = new RedirectResponse($url);
$response->setContent($redirectResponse->getContent());
$response->setStatusCode($redirectResponse->getStatusCode());
$response->headers = $redirectResponse->headers;
}
$response->headers->set(PlatformRequest::HEADER_CONTEXT_TOKEN, $contextToken);