diff --git a/.env.dist b/.env.dist index a25e8c2c..d6271d57 100644 --- a/.env.dist +++ b/.env.dist @@ -8,3 +8,7 @@ SHORTCODE_CHARS= DB_USER= DB_PASSWORD= DB_NAME= + +# Rest authentication +REST_USER= +REST_PASSWORD= diff --git a/config/autoload/rest.global.php b/config/autoload/rest.global.php new file mode 100644 index 00000000..6e3fc216 --- /dev/null +++ b/config/autoload/rest.global.php @@ -0,0 +1,9 @@ + [ + 'username' => getenv('REST_USER'), + 'password' => getenv('REST_PASSWORD'), + ], + +]; diff --git a/src/Entity/RestToken.php b/src/Entity/RestToken.php new file mode 100644 index 00000000..d23dc10f --- /dev/null +++ b/src/Entity/RestToken.php @@ -0,0 +1,89 @@ +updateExpiration(); + } + + /** + * @return \DateTime + */ + public function getExpirationDate() + { + return $this->expirationDate; + } + + /** + * @param \DateTime $expirationDate + * @return $this + */ + public function setExpirationDate($expirationDate) + { + $this->expirationDate = $expirationDate; + return $this; + } + + /** + * @return string + */ + public function getToken() + { + return $this->token; + } + + /** + * @param string $token + * @return $this + */ + public function setToken($token) + { + $this->token = $token; + return $this; + } + + /** + * @return bool + */ + public function isExpired() + { + return new \DateTime() > $this->expirationDate; + } + + /** + * Updates the expiration of the token, setting it to the default interval in the future + * @return $this + */ + public function updateExpiration() + { + return $this->setExpirationDate((new \DateTime())->add(new \DateInterval(self::DEFAULT_INTERVAL))); + } +}