|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the cilogon/oauth2-orcid library. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @author Terry Fleury <[email protected]> |
|
10
|
|
|
* @copyright 2016 University of Illinois |
|
11
|
|
|
* @license https://opensource.org/licenses/NCSA NCSA |
|
12
|
|
|
* @link https://github.com/cilogon/oauth2-orcid GitHub |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace CILogon\OAuth2\Client\Provider; |
|
16
|
|
|
|
|
17
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
|
18
|
|
|
|
|
19
|
|
|
class ORCIDResourceOwner implements ResourceOwnerInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Raw response |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $response; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Creates new resource owner. |
|
30
|
|
|
* |
|
31
|
|
|
* @param array $response |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(array $response = array()) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->response = $response; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get resource owner id. This corresponds to the "full" ORCID identifier (with |
|
40
|
|
|
* the http://orcid.org/ prefix). |
|
41
|
|
|
* |
|
42
|
|
|
* @return string|null |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getId() |
|
45
|
|
|
{ |
|
46
|
|
|
return @$this->response['orcid-identifier']['uri'] ?: null; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get resource owner display name. This corresponds to the |
|
51
|
|
|
* "Published Name", * a.k.a. "credit-name". |
|
52
|
|
|
* |
|
53
|
|
|
* @return string|null |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getName() |
|
56
|
|
|
{ |
|
57
|
|
|
return @$this->response['person']['name']['credit-name']['value'] ?: null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get resource owner given (first) name. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string|null |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getGivenName() |
|
66
|
|
|
{ |
|
67
|
|
|
return @$this->response['person']['name']['given-names']['value'] ?: null; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Get resource owner given (first) name. Alias for getGivenName(). |
|
72
|
|
|
* |
|
73
|
|
|
* @return string|null |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getFirstName() |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->getGivenName(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get resource owner family (last) name. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string|null |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getFamilyName() |
|
86
|
|
|
{ |
|
87
|
|
|
return @$this->response['person']['name']['family-name']['value'] ?: null; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Get resource owner family (last) name. Alias for getFamilyName(); |
|
92
|
|
|
* |
|
93
|
|
|
* @return string|null |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getLastName() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->getFamilyName(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get other resource owner names, a.k.a. "Also Known As" names. |
|
102
|
|
|
* |
|
103
|
|
|
* @return array |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getOtherNames() |
|
106
|
|
|
{ |
|
107
|
|
|
$retval = array(); |
|
108
|
|
|
foreach (@$this->response['person']['other-names']['other-name'] as $name) { |
|
109
|
|
|
if (isset($name['content'])) { |
|
110
|
|
|
$retval[] = @$name['content']; |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $retval; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* Get resource owner email address. As there can be multiple email |
|
119
|
|
|
* addresses for a user, loop through all of them with preference to the |
|
120
|
|
|
* one marked as 'primary'. If no primary email address exists, then use |
|
121
|
|
|
* the last one listed. |
|
122
|
|
|
* |
|
123
|
|
|
* @return string|null |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getEmail() |
|
126
|
|
|
{ |
|
127
|
|
|
$retval = null; |
|
128
|
|
|
foreach (@$this->response['person']['emails']['email'] as $email) { |
|
129
|
|
|
if (@$email['primary']) { |
|
130
|
|
|
$retval = @$email['email']; |
|
131
|
|
|
break; |
|
132
|
|
|
} elseif (is_null($retval)) { |
|
133
|
|
|
$retval = @$email['email']; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return $retval; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Get resource owner PRIMARY email address. As there can be multiple email |
|
142
|
|
|
* addresses for a user, loop through all of them looking for the one |
|
143
|
|
|
* marked as 'primary'. |
|
144
|
|
|
* |
|
145
|
|
|
* @return string|null |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getPrimaryEmail() |
|
148
|
|
|
{ |
|
149
|
|
|
$retval = null; |
|
150
|
|
|
foreach (@$this->response['person']['emails']['email'] as $email) { |
|
151
|
|
|
if (@$email['primary']) { |
|
152
|
|
|
$retval = @$email['email']; |
|
153
|
|
|
break; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
return $retval; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Get all resource owner email addresses. |
|
162
|
|
|
* |
|
163
|
|
|
* @return array |
|
164
|
|
|
*/ |
|
165
|
|
|
public function getEmails() |
|
166
|
|
|
{ |
|
167
|
|
|
$retval = array(); |
|
168
|
|
|
foreach (@$this->response['person']['emails']['email'] as $email) { |
|
169
|
|
|
if (isset($email['email'])) { |
|
170
|
|
|
$retval[] = @$email['email']; |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
return $retval; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* Get AMR (AuthnMethodRef) used during authentication. |
|
179
|
|
|
* This value is available only with the Member API. |
|
180
|
|
|
* Can be one of 'mfa', 'pwd', or null. |
|
181
|
|
|
* |
|
182
|
|
|
* @return string|null |
|
183
|
|
|
*/ |
|
184
|
|
|
public function getAmr() |
|
185
|
|
|
{ |
|
186
|
|
|
return @$this->response['amr'] ?: null; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/** |
|
190
|
|
|
* Return all of the owner details available as an array. |
|
191
|
|
|
* |
|
192
|
|
|
* @return array |
|
193
|
|
|
*/ |
|
194
|
|
|
public function toArray() |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->response; |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|