SetLogoutCookie.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License").
  6. * You may not use this file except in compliance with the License.
  7. * A copy of the License is located at
  8. *
  9. * http://aws.amazon.com/apache2.0
  10. *
  11. * or in the "license" file accompanying this file. This file is distributed
  12. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  13. * express or implied. See the License for the specific language governing
  14. * permissions and limitations under the License.
  15. */
  16. namespace Amazon\Login\Observer;
  17. use Amazon\Core\Helper\Data;
  18. use Magento\Framework\Event\Observer;
  19. use Magento\Framework\Event\ObserverInterface;
  20. use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
  21. use Magento\Framework\Stdlib\CookieManagerInterface;
  22. class SetLogoutCookie implements ObserverInterface
  23. {
  24. const LOGGEDOUT_COOKIE = 'amz_auth_logout';
  25. /**
  26. * @var CookieManagerInterface
  27. */
  28. private $cookieManager;
  29. /**
  30. * @var CookieMetadataFactory
  31. */
  32. private $cookieMetadataFactory;
  33. /**
  34. * @var Data
  35. */
  36. private $coreHelper;
  37. /**
  38. * @param CookieManagerInterface $cookieManager
  39. * @param CookieMetadataFactory $cookieMetadataFactory
  40. * @param Data $coreHelper
  41. */
  42. public function __construct(
  43. CookieManagerInterface $cookieManager,
  44. CookieMetadataFactory $cookieMetadataFactory,
  45. Data $coreHelper
  46. ) {
  47. $this->cookieManager = $cookieManager;
  48. $this->cookieMetadataFactory = $cookieMetadataFactory;
  49. $this->coreHelper = $coreHelper;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function execute(Observer $observer)
  55. {
  56. if ($this->coreHelper->isLwaEnabled()) {
  57. $cookieMeta = $this->cookieMetadataFactory
  58. ->createPublicCookieMetadata()
  59. ->setDuration(86400)
  60. ->setPath('/')
  61. ->setHttpOnly(false);
  62. $this->cookieManager->setPublicCookie(self::LOGGEDOUT_COOKIE, '1', $cookieMeta);
  63. }
  64. }
  65. }