| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\AI_Authorization\Domain; |
| 4 |
|
| 5 |
/** |
| 6 |
* Class Code_Verifier representing a challenge code and its creation time. |
| 7 |
* This is used during the authorization process to verify the user requesting a token. |
| 8 |
*/ |
| 9 |
class Code_Verifier { |
| 10 |
|
| 11 |
/** |
| 12 |
* The code. |
| 13 |
* |
| 14 |
* @var string |
| 15 |
*/ |
| 16 |
private $code; |
| 17 |
|
| 18 |
/** |
| 19 |
* The time the code was created. |
| 20 |
* |
| 21 |
* @var int |
| 22 |
*/ |
| 23 |
private $created_at; |
| 24 |
|
| 25 |
/** |
| 26 |
* Code_Verifier constructor. |
| 27 |
* |
| 28 |
* @param string $code The code. |
| 29 |
* @param int $created_at The time the code was created. |
| 30 |
*/ |
| 31 |
public function __construct( string $code, int $created_at ) { |
| 32 |
$this->code = $code; |
| 33 |
$this->created_at = $created_at; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get the code. |
| 38 |
* |
| 39 |
* @return string The code. |
| 40 |
*/ |
| 41 |
public function get_code(): string { |
| 42 |
return $this->code; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Get the creation time of the code. |
| 47 |
* |
| 48 |
* @return int The creation time of the code. |
| 49 |
*/ |
| 50 |
public function get_created_at(): int { |
| 51 |
return $this->created_at; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Check if the code is expired. |
| 56 |
* |
| 57 |
* @param int $validity_in_seconds The validity of the code in seconds. |
| 58 |
* |
| 59 |
* @return bool True if the code is expired, false otherwise. |
| 60 |
*/ |
| 61 |
public function is_expired( int $validity_in_seconds ): bool { |
| 62 |
return $this->created_at < ( \time() - $validity_in_seconds ); |
| 63 |
} |
| 64 |
} |
| 65 |
|