mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-09 16:28:00 +08:00
parent
a2ec25fbd4
commit
33a4692c06
3 changed files with 22 additions and 7 deletions
|
@ -21,9 +21,6 @@ abstract class SASL
|
|||
final public static function factory(string $type)
|
||||
{
|
||||
if (\preg_match('/^([A-Z2]+)(?:-(.+))?$/Di', $type, $m)) {
|
||||
if ('XOAUTH2' === $m[1] || 'OAUTHBEARER' === $m[1]) {
|
||||
$m[1] = 'OAUTH';
|
||||
}
|
||||
$class = __CLASS__ . "\\{$m[1]}";
|
||||
if (\class_exists($class) && $class::isSupported($m[2] ?? '')) {
|
||||
return new $class($m[2] ?? '');
|
||||
|
@ -35,9 +32,6 @@ abstract class SASL
|
|||
public static function isSupported(string $type) : bool
|
||||
{
|
||||
if (\preg_match('/^([A-Z2]+)(?:-(.+))?$/Di', $type, $m)) {
|
||||
if ('XOAUTH2' === $m[1] || 'OAUTHBEARER' === $m[1]) {
|
||||
$m[1] = 'OAUTH';
|
||||
}
|
||||
$class = __CLASS__ . "\\{$m[1]}";
|
||||
return \class_exists($class) && $class::isSupported($m[2] ?? '');
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace SnappyMail\SASL;
|
||||
|
||||
class OAuth extends \SnappyMail\SASL
|
||||
class OAuthBearer extends \SnappyMail\SASL
|
||||
{
|
||||
public function authenticate(string $username, string $passphrase, ?string $authzid = null) : string
|
||||
{
|
21
snappymail/v/0.0.0/app/libraries/snappymail/sasl/xoauth2.php
Normal file
21
snappymail/v/0.0.0/app/libraries/snappymail/sasl/xoauth2.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* https://datatracker.ietf.org/doc/html/rfc7628
|
||||
* https://developers.google.com/gmail/imap/xoauth2-protocol
|
||||
*/
|
||||
|
||||
|
||||
namespace SnappyMail\SASL;
|
||||
|
||||
class XOAuth2 extends \SnappyMail\SASL
|
||||
{
|
||||
public function authenticate(string $username, string $passphrase, ?string $authzid = null) : string
|
||||
{
|
||||
return $this->encode("user={$username}\x01auth=Bearer {$passphrase}\x01\x01");
|
||||
}
|
||||
|
||||
public static function isSupported(string $param) : bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue