Files
provider_jmapc/lib/Providers/ServiceIdentityBasic.php
2026-02-10 20:33:10 -05:00

88 lines
1.9 KiB
PHP

<?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;
}
}