XOAuth2Authenticator.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Mailer\Transport\Smtp\Auth;
  11. use Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport;
  12. /**
  13. * Handles XOAUTH2 authentication.
  14. *
  15. * @author xu.li<AthenaLightenedMyPath@gmail.com>
  16. *
  17. * @see https://developers.google.com/google-apps/gmail/xoauth2_protocol
  18. */
  19. class XOAuth2Authenticator implements AuthenticatorInterface
  20. {
  21. public function getAuthKeyword(): string
  22. {
  23. return 'XOAUTH2';
  24. }
  25. /**
  26. * @see https://developers.google.com/google-apps/gmail/xoauth2_protocol#the_sasl_xoauth2_mechanism
  27. */
  28. public function authenticate(EsmtpTransport $client): void
  29. {
  30. $client->executeCommand('AUTH XOAUTH2 '.base64_encode('user='.$client->getUsername()."\1auth=Bearer ".$client->getPassword()."\1\1")."\r\n", [235]);
  31. }
  32. }