Skip to content

Commit 513cdae

Browse files
committed
add bearer support
1 parent 7de995c commit 513cdae

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

solid/lib/BearerFactoryTrait.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace OCA\Solid;
4+
5+
use DateInterval;
6+
use OCP\IDBConnection;
7+
use Pdsinterop\Solid\Auth\Utils\Bearer;
8+
use Pdsinterop\Solid\Auth\Utils\JtiValidator;
9+
10+
trait BearerFactoryTrait
11+
{
12+
////////////////////////////// CLASS PROPERTIES \\\\\\\\\\\\\\\\\\\\\\\\\\\\
13+
14+
private IDBConnection $connection;
15+
private DateInterval $validFor;
16+
17+
//////////////////////////////// PUBLIC API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
18+
19+
final public function getBearer(): Bearer
20+
{
21+
$interval = $this->getBearerValidFor();
22+
23+
$replayDetector = new JtiReplayDetector($interval, $this->connection);
24+
25+
$jtiValidator = new JtiValidator($replayDetector);
26+
27+
return new Bearer($jtiValidator);
28+
}
29+
30+
final public function getBearerValidFor(): DateInterval
31+
{
32+
static $validFor;
33+
34+
if ($validFor === null) {
35+
$validFor = new DateInterval('PT10M');
36+
}
37+
38+
return $validFor;
39+
}
40+
41+
final public function setJtiStorage(IDBConnection $connection): void
42+
{
43+
$this->connection = $connection;
44+
}
45+
46+
////////////////////////////// UTILITY METHODS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
47+
}

0 commit comments

Comments
 (0)