Skip to content

Commit d472c2d

Browse files
committed
add jti store
1 parent 3bf3894 commit d472c2d

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

lib/JtiStore.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
namespace Pdsinterop\PhpSolid;
3+
4+
class JtiStore {
5+
private static $pdo;
6+
private static function connect() {
7+
if (!isset(self::$pdo)) {
8+
self::$pdo = new \PDO("sqlite:" . DBPATH);
9+
}
10+
}
11+
12+
public static function hasJti($jti) {
13+
self::connect();
14+
$now = new \DateTime();
15+
16+
$query = self::$pdo->prepare(
17+
'SELECT jti FROM jti WHERE jti=:jti AND expires>:now'
18+
);
19+
$query->execute([
20+
':jti' => $jti,
21+
':now' => $now->getTimestamp()
22+
]);
23+
$result = $query->fetchAll();
24+
if (sizeof($result) === 1) {
25+
return true;
26+
}
27+
return false;
28+
}
29+
30+
public static function saveJti($jti) {
31+
self::connect();
32+
$query = self::$pdo->prepare(
33+
'INSERT INTO jti VALUES(:jti, :expires)'
34+
);
35+
$expires = new \DateTime();
36+
$expires->add(new \DateInterval("PT1H"));
37+
$query->execute([
38+
':jti' => $jti,
39+
':expires' => $expires->getTimestamp()
40+
]);
41+
}
42+
}

0 commit comments

Comments
 (0)