From 33a4692c069df0d35fb0e0ba1e527c19891cb75d Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Thu, 8 Dec 2022 12:13:35 +0100 Subject: [PATCH] Improve solution for #758 and #759 --- .../v/0.0.0/app/libraries/snappymail/sasl.php | 6 ------ .../sasl/{oauth.php => oauthbearer.php} | 2 +- .../app/libraries/snappymail/sasl/xoauth2.php | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) rename snappymail/v/0.0.0/app/libraries/snappymail/sasl/{oauth.php => oauthbearer.php} (90%) create mode 100644 snappymail/v/0.0.0/app/libraries/snappymail/sasl/xoauth2.php diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/sasl.php b/snappymail/v/0.0.0/app/libraries/snappymail/sasl.php index d54015da2..fd446371e 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/sasl.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/sasl.php @@ -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] ?? ''); } diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/sasl/oauth.php b/snappymail/v/0.0.0/app/libraries/snappymail/sasl/oauthbearer.php similarity index 90% rename from snappymail/v/0.0.0/app/libraries/snappymail/sasl/oauth.php rename to snappymail/v/0.0.0/app/libraries/snappymail/sasl/oauthbearer.php index 8a2c5ad2a..66bfb84a2 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/sasl/oauth.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/sasl/oauthbearer.php @@ -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 { diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/sasl/xoauth2.php b/snappymail/v/0.0.0/app/libraries/snappymail/sasl/xoauth2.php new file mode 100644 index 000000000..bf1563013 --- /dev/null +++ b/snappymail/v/0.0.0/app/libraries/snappymail/sasl/xoauth2.php @@ -0,0 +1,21 @@ +encode("user={$username}\x01auth=Bearer {$passphrase}\x01\x01"); + } + + public static function isSupported(string $param) : bool + { + return true; + } +}