-
Notifications
You must be signed in to change notification settings - Fork 1
/
Client.php
46 lines (39 loc) · 1.1 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace WadoJwt\Client;
use Firebase\JWT\JWT;
class Client
{
protected $key;
protected $url;
protected $pacs;
public function __construct($url, $key, $algorithm, $pacs = null)
{
$this->url = $url;
$this->key = $key;
$this->algorithm = $algorithm;
$this->pacs = $pacs;
}
public function getJwt($studyUid, $seriesUid, $objectUid, $contentType)
{
$expire = (60*5); // 5 minutes
$token = [
'iat' => time(),
'exp' => time() + $expire,
'studyUid' => $studyUid,
'seriesUid' => $seriesUid,
'objectUid' => $objectUid,
'contentType' => $contentType
];
if ($this->pacs) {
$token['pacs'] = $this->pacs;
}
$jwt = JWT::encode($token, $this->key, $this->algorithm);
return $jwt;
}
public function getUrl($studyUid, $seriesUid, $objectUid, $contentType)
{
$jwt = $this->getJwt($studyUid, $seriesUid, $objectUid, $contentType);
$url = $this->url . '?jwt=' . $jwt;
return $url;
}
}