mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-30 13:34:28 +02:00
Added own APIToken authenticator, so we can wrap the used API token inside the symfony security token
This commit is contained in:
parent
bcd41c4d9b
commit
8dad143f8d
10 changed files with 391 additions and 67 deletions
|
@ -58,6 +58,12 @@ class ApiToken
|
|||
#[ORM\Column(length: 68, unique: true)]
|
||||
private string $token;
|
||||
|
||||
#[ORM\Column(type: Types::SMALLINT, enumType: ApiTokenLevel::class)]
|
||||
private ApiTokenLevel $level = ApiTokenLevel::READ_ONLY;
|
||||
|
||||
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
|
||||
private ?\DateTimeInterface $last_time_used = null;
|
||||
|
||||
public function __construct(ApiTokenType $tokenType = ApiTokenType::PERSONAL_ACCESS_TOKEN)
|
||||
{
|
||||
// Generate a rondom token on creation. The tokenType is 3 characters long (plus underscore), so the token is 68 characters long.
|
||||
|
@ -121,5 +127,36 @@ class ApiToken
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last time the token was used to authenticate or null if it was never used.
|
||||
* @return \DateTimeInterface|null
|
||||
*/
|
||||
public function getLastTimeUsed(): ?\DateTimeInterface
|
||||
{
|
||||
return $this->last_time_used;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the last time the token was used to authenticate.
|
||||
* @param \DateTimeInterface|null $last_time_used
|
||||
* @return ApiToken
|
||||
*/
|
||||
public function setLastTimeUsed(?\DateTimeInterface $last_time_used): ApiToken
|
||||
{
|
||||
$this->last_time_used = $last_time_used;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLevel(): ApiTokenLevel
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
|
||||
public function setLevel(ApiTokenLevel $level): ApiToken
|
||||
{
|
||||
$this->level = $level;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue