Initial commit
This commit is contained in:
15
src/AuthTypes/Authenticable.php
Normal file
15
src/AuthTypes/Authenticable.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pdahal\Xmpp\AuthTypes;
|
||||
|
||||
interface Authenticable
|
||||
{
|
||||
/**
|
||||
* Based on auth type, return the right format of credentials to be sent to the server.
|
||||
*/
|
||||
public function encodedCredentials(): string;
|
||||
|
||||
public function getName(): string;
|
||||
}
|
24
src/AuthTypes/Authentication.php
Normal file
24
src/AuthTypes/Authentication.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pdahal\Xmpp\AuthTypes;
|
||||
|
||||
use Pdahal\Xmpp\Options;
|
||||
use Pdahal\Xmpp\Xml\Xml;
|
||||
|
||||
abstract class Authentication implements Authenticable
|
||||
{
|
||||
use Xml;
|
||||
|
||||
protected string $name;
|
||||
|
||||
public function __construct(protected Options $options)
|
||||
{
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
16
src/AuthTypes/DigestMD5.php
Normal file
16
src/AuthTypes/DigestMD5.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pdahal\Xmpp\AuthTypes;
|
||||
|
||||
class DigestMD5 extends Authentication
|
||||
{
|
||||
protected string $name = 'DIGEST-MD5';
|
||||
|
||||
public function encodedCredentials(): string
|
||||
{
|
||||
$credentials = "\x00{$this->options->getUsername()}\x00{$this->options->getPassword()}";
|
||||
return self::quote(sha1($credentials));
|
||||
}
|
||||
}
|
16
src/AuthTypes/Plain.php
Normal file
16
src/AuthTypes/Plain.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pdahal\Xmpp\AuthTypes;
|
||||
|
||||
class Plain extends Authentication
|
||||
{
|
||||
protected string $name = 'PLAIN';
|
||||
|
||||
public function encodedCredentials(): string
|
||||
{
|
||||
$credentials = "\x00{$this->options->getUsername()}\x00{$this->options->getPassword()}";
|
||||
return self::quote(base64_encode($credentials));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user