forked from XeroAPI/xero-php-oauth2-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.php
86 lines (75 loc) · 1.56 KB
/
storage.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
class StorageClass
{
function __construct() {
if( !isset($_SESSION) ){
$this->init_session();
}
}
public function init_session(){
session_start();
}
public function getSession() {
return $_SESSION['oauth2'];
}
public function startSession($token, $secret, $expires = null)
{
session_start();
}
public function setToken($token, $expires = null, $tenantId, $refreshToken, $idToken)
{
$_SESSION['oauth2'] = [
'token' => $token,
'expires' => $expires,
'tenant_id' => $tenantId,
'refresh_token' => $refreshToken,
'id_token' => $idToken
];
}
public function getToken()
{
//If it doesn't exist or is expired, return null
if (empty($this->getSession())
|| ($_SESSION['oauth2']['expires'] !== null
&& $_SESSION['oauth2']['expires'] <= time())
) {
return null;
}
return $this->getSession();
}
public function getAccessToken()
{
return $_SESSION['oauth2']['token'];
}
public function getRefreshToken()
{
return $_SESSION['oauth2']['refresh_token'];
}
public function getExpires()
{
return $_SESSION['oauth2']['expires'];
}
public function getXeroTenantId()
{
return $_SESSION['oauth2']['tenant_id'];
}
public function getIdToken()
{
return $_SESSION['oauth2']['id_token'];
}
public function getHasExpired()
{
if (!empty($this->getSession()))
{
if(time() > $this->getExpires())
{
return true;
} else {
return false;
}
} else {
return true;
}
}
}
?>