Initial commit
This commit is contained in:
87
lib/Providers/ServiceIdentityBasic.php
Normal file
87
lib/Providers/ServiceIdentityBasic.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
namespace KTXM\ProviderJmapc\Providers;
|
||||
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
|
||||
|
||||
/**
|
||||
* JMAP Service Basic Identity
|
||||
*
|
||||
* Username/password authentication for JMAP.
|
||||
*/
|
||||
class ServiceIdentityBasic implements ResourceServiceIdentityBasic
|
||||
{
|
||||
public function __construct(
|
||||
private string $identity = '',
|
||||
private string $secret = '',
|
||||
) {}
|
||||
|
||||
public function toStore(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::TYPE_BASIC,
|
||||
'identity' => $this->identity,
|
||||
'secret' => $this->secret,
|
||||
];
|
||||
}
|
||||
|
||||
public function fromStore(array $data): self
|
||||
{
|
||||
return new self(
|
||||
identity: $data['identity'] ?? '',
|
||||
secret: $data['secret'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'type' => self::TYPE_BASIC,
|
||||
'identity' => $this->identity,
|
||||
// Password intentionally omitted from serialization for security
|
||||
];
|
||||
}
|
||||
public function jsonDeserialize(array|string $data): static
|
||||
{
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
$this->identity = $data['identity'] ?? '';
|
||||
$this->secret = $data['secret'] ?? '';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function type(): string
|
||||
{
|
||||
return self::TYPE_BASIC;
|
||||
}
|
||||
|
||||
public function getIdentity(): string
|
||||
{
|
||||
return $this->identity;
|
||||
}
|
||||
|
||||
public function setIdentity(string $value): void
|
||||
{
|
||||
$this->identity = $value;
|
||||
}
|
||||
|
||||
public function getSecret(): string
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
public function setSecret(string $value): void
|
||||
{
|
||||
$this->secret = $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user