|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Generation 2 OAuth2 client |
|
5
|
|
|
* |
|
6
|
|
|
* @package OAuth2-Generation2 |
|
7
|
|
|
* @author Manuele Vaccari <[email protected]> |
|
8
|
|
|
* @copyright Copyright (c) 2017-2020 Manuele Vaccari <[email protected]> |
|
9
|
|
|
* @license https://github.com/D3strukt0r/oauth2-generation-2/blob/master/LICENSE.txt GNU General Public License v3.0 |
|
10
|
|
|
* @link https://github.com/D3strukt0r/oauth2-generation-2 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Generation2\OAuth2\Client\Provider; |
|
14
|
|
|
|
|
15
|
|
|
use DateTime; |
|
16
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The Class which can be used with league/oauth2-client. |
|
20
|
|
|
*/ |
|
21
|
|
|
class Generation2ResourceOwner implements ResourceOwnerInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Raw response. |
|
25
|
|
|
* |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $response; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Creates new resource owner. |
|
32
|
|
|
* |
|
33
|
|
|
* @param array $response Data received from the server about the user |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(array $response = []) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->response = $response; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns the identifier of the authorized resource owner. |
|
42
|
|
|
* |
|
43
|
|
|
* @return int|null |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getId() |
|
46
|
|
|
{ |
|
47
|
|
|
return (int) $this->response['id'] ?: null; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Return the username. |
|
52
|
|
|
* |
|
53
|
|
|
* @return string|null |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getUsername() |
|
56
|
|
|
{ |
|
57
|
|
|
return $this->response['username'] ?: null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Return the email. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string|null |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getEmail() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->response['email'] ?: null; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Return the first name. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string|null |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getFirstName() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->response['name'] ?: null; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Return the surname. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string|null |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getSurname() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->response['surname'] ?: null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Return the birthday. |
|
92
|
|
|
* |
|
93
|
|
|
* @return DateTime|null |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getBirthday() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->response['birthday'] ? (new DateTime())->setTimestamp($this->response['birthday']) : null; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Return the surname. |
|
102
|
|
|
* |
|
103
|
|
|
* @return array|null |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getActiveAddress() |
|
106
|
|
|
{ |
|
107
|
|
|
if (null === $this->getAddresses()) { |
|
108
|
|
|
return null; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if (1 === count($this->getAddresses())) { |
|
112
|
|
|
foreach ($this->getAddresses() as $address) { |
|
113
|
|
|
return $address; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if (null === $this->response['active_address']) { |
|
118
|
|
|
return null; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return $this->getAddresses()[$this->response['active_address']]; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Return the surname. |
|
126
|
|
|
* |
|
127
|
|
|
* @return array|null |
|
128
|
|
|
*/ |
|
129
|
|
|
public function getAddresses() |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->response['addresses'] ?: null; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Return the subscription. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string|null |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getSubscription() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->response['subscription_type'] ?: null; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* Return all of the owner details available as an array. |
|
146
|
|
|
* |
|
147
|
|
|
* @return array |
|
148
|
|
|
*/ |
|
149
|
|
|
public function toArray() |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->response; |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|