generated from Nodarx/template
ad6b7c5eba
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
*/
|
|
|
|
namespace KTXM\ProviderImap\Smtp\Auth;
|
|
|
|
/**
|
|
* Supported SASL authentication mechanisms, in preference order.
|
|
*/
|
|
enum AuthMechanism: string
|
|
{
|
|
case Plain = 'PLAIN';
|
|
case Login = 'LOGIN';
|
|
|
|
/**
|
|
* Select the most preferred mechanism the server advertises.
|
|
*
|
|
* @param list<string> $advertised mechanisms offered by the server (uppercased)
|
|
*/
|
|
public static function select(array $advertised): ?self
|
|
{
|
|
foreach ([self::Plain, self::Login] as $mechanism) {
|
|
if (in_array($mechanism->value, $advertised, true)) {
|
|
return $mechanism;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* The initial AUTH response for the PLAIN mechanism:
|
|
* base64( authzid NUL authcid NUL passwd ).
|
|
*/
|
|
public static function plainToken(string $username, string $password): string
|
|
{
|
|
return base64_encode("\0" . $username . "\0" . $password);
|
|
}
|
|
}
|