| 27 | | final class RefreshTokenRepository extends AbstractRepository implements RefreshTokenRepositoryInterface |
| 28 | | { |
| 29 | | public function getNewRefreshToken(): ?RefreshTokenEntityInterface |
| 30 | | { |
| 31 | | return new RefreshTokenEntity(); |
| 32 | | } |
| 33 | | |
| 34 | | public function persistNewRefreshToken(RefreshTokenEntityInterface $refreshTokenEntity): void |
| 35 | | { |
| 36 | | $insert = sprintf( |
| 37 | | "INSERT INTO %s (identifier, access_token_identifier, revoked, expires_at, created) |
| 38 | | VALUES ('%s', '%s', 0, '%s', %s)", |
| 39 | | $this->table('faqoauth_refresh_tokens'), |
| 40 | | $this->db()->escape($refreshTokenEntity->getIdentifier()), |
| 41 | | $this->db()->escape($refreshTokenEntity->getAccessToken()->getIdentifier()), |
| 42 | | $refreshTokenEntity->getExpiryDateTime()->format('Y-m-d H:i:s'), |
| 43 | | $this->db()->now(), |
| 44 | | ); |
| 45 | | |
| 46 | | if ($this->db()->query($insert) === false) { |
| 47 | | throw UniqueTokenIdentifierConstraintViolationException::create(); |
| 48 | | } |
| 49 | | } |
| 50 | | |
| 51 | | public function revokeRefreshToken(string $tokenId): void |
| 52 | | { |
| 53 | | $this->db()->query(sprintf( |
| 54 | | "UPDATE %s SET revoked = 1 WHERE identifier = '%s'", |
| 55 | | $this->table('faqoauth_refresh_tokens'), |
| 56 | | $this->db()->escape($tokenId), |
| 57 | | )); |
| 58 | | } |
| 59 | | |
| 60 | | public function isRefreshTokenRevoked(string $tokenId): bool |
| 61 | | { |
| 62 | | $result = $this->db()->query(sprintf( |
| 63 | | "SELECT revoked FROM %s WHERE identifier = '%s'", |
| 64 | | $this->table('faqoauth_refresh_tokens'), |
| 65 | | $this->db()->escape($tokenId), |
| 66 | | )); |
| 67 | | |
| 68 | | if ($result === false) { |
| 69 | | return true; |
| 70 | | } |
| 71 | | |
| 72 | | $row = $this->db()->fetchObject($result); |
| 73 | | if (!is_object($row)) { |
| 74 | | return true; |
| 75 | | } |
| 76 | | |
| 77 | | return (int) ($row->revoked ?? 1) === 1; |
| 78 | | } |
| 79 | | } |