chg: usr: add modern Webauthn authentication #4
This commit is contained in:
171
src/Entity/WebAuthnCredential.php
Normal file
171
src/Entity/WebAuthnCredential.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* This file is part of the SplendidBear Websites' projects.
|
||||
*
|
||||
* Copyright (c) 2026 @ www.splendidbear.org
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\WebAuthnCredentialRepository;
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping\Column;
|
||||
use Doctrine\ORM\Mapping\Entity;
|
||||
use Doctrine\ORM\Mapping\GeneratedValue;
|
||||
use Doctrine\ORM\Mapping\Id;
|
||||
use Doctrine\ORM\Mapping\JoinColumn;
|
||||
use Doctrine\ORM\Mapping\ManyToOne;
|
||||
use Doctrine\ORM\Mapping\Table;
|
||||
|
||||
/**
|
||||
* Class WebAuthnCredential
|
||||
*
|
||||
* @package App\Entity
|
||||
* @author Lang <https://www.splendidbear.org>
|
||||
* @category Class
|
||||
* @license https://www.gnu.org/licenses/lgpl-3.0.en.html GNU Lesser General Public License
|
||||
* @link www.splendidbear.org
|
||||
* @since 2026. 04. 12.
|
||||
*/
|
||||
#[Table(name: 'app_webauthn_credential')]
|
||||
#[Entity(repositoryClass: WebAuthnCredentialRepository::class)]
|
||||
class WebAuthnCredential
|
||||
{
|
||||
#[Id, GeneratedValue, Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ManyToOne(targetEntity: User::class)]
|
||||
#[JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
private ?User $user = null;
|
||||
|
||||
#[Column(type: Types::TEXT)]
|
||||
private ?string $credentialData = null;
|
||||
|
||||
#[Column(length: 255)]
|
||||
private ?string $credentialName = null;
|
||||
|
||||
#[Column(type: Types::DATETIME_MUTABLE)]
|
||||
private ?DateTime $createdAt = null;
|
||||
|
||||
#[Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
||||
private ?DateTime $lastUsedAt = null;
|
||||
|
||||
#[Column]
|
||||
private bool $isBackupEligible = false;
|
||||
|
||||
#[Column]
|
||||
private bool $isBackupAuthenticated = false;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new DateTime();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?User $user): self
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCredentialData(): ?string
|
||||
{
|
||||
return $this->credentialData;
|
||||
}
|
||||
|
||||
public function setCredentialData(?string $credentialData): self
|
||||
{
|
||||
$this->credentialData = $credentialData;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCredentialName(): ?string
|
||||
{
|
||||
return $this->credentialName;
|
||||
}
|
||||
|
||||
public function setCredentialName(?string $credentialName): self
|
||||
{
|
||||
$this->credentialName = $credentialName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCreatedAt(): ?DateTime
|
||||
{
|
||||
return $this->createdAt;
|
||||
}
|
||||
|
||||
public function setCreatedAt(?DateTime $createdAt): self
|
||||
{
|
||||
$this->createdAt = $createdAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLastUsedAt(): ?DateTime
|
||||
{
|
||||
return $this->lastUsedAt;
|
||||
}
|
||||
|
||||
public function setLastUsedAt(?DateTime $lastUsedAt): self
|
||||
{
|
||||
$this->lastUsedAt = $lastUsedAt;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isBackupEligible(): bool
|
||||
{
|
||||
return $this->isBackupEligible;
|
||||
}
|
||||
|
||||
public function setBackupEligible(bool $isBackupEligible): self
|
||||
{
|
||||
$this->isBackupEligible = $isBackupEligible;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isBackupAuthenticated(): bool
|
||||
{
|
||||
return $this->isBackupAuthenticated;
|
||||
}
|
||||
|
||||
public function setBackupAuthenticated(bool $isBackupAuthenticated): self
|
||||
{
|
||||
$this->isBackupAuthenticated = $isBackupAuthenticated;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPublicKeyCredentialSource()
|
||||
{
|
||||
// Return the raw credential data (JSON decoded)
|
||||
if ($this->credentialData === null) {
|
||||
return null;
|
||||
}
|
||||
return json_decode($this->credentialData, true);
|
||||
}
|
||||
|
||||
public function setPublicKeyCredentialSource($source): self
|
||||
{
|
||||
// Handle both array and object input
|
||||
if (is_array($source)) {
|
||||
$this->credentialData = json_encode($source);
|
||||
} else {
|
||||
$this->credentialData = (string)$source;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user