|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Parroauth2\Client\OpenID\EndPoint\Userinfo; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Response of the userinfo endpoint |
|
7
|
|
|
* |
|
8
|
|
|
* @see https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.5.3.2 |
|
9
|
|
|
* |
|
10
|
|
|
* @psalm-immutable |
|
11
|
|
|
*/ |
|
12
|
|
|
class UserinfoResponse |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var array<string, mixed> |
|
16
|
|
|
*/ |
|
17
|
|
|
private $data; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* UserinfoResponse constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @param array<string, mixed> $data |
|
23
|
|
|
*/ |
|
24
|
11 |
|
public function __construct(array $data) |
|
25
|
|
|
{ |
|
26
|
11 |
|
$this->data = $data; |
|
27
|
11 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get the subject (i.e. The user identifier) |
|
31
|
|
|
* |
|
32
|
|
|
* @return string |
|
33
|
|
|
*/ |
|
34
|
10 |
|
public function subject(): string |
|
35
|
|
|
{ |
|
36
|
10 |
|
return $this->data['sub']; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* End-User's full name in displayable form including all name parts, |
|
41
|
|
|
* possibly including titles and suffixes, ordered according to the End-User's locale and preferences. |
|
42
|
|
|
* |
|
43
|
|
|
* @return string|null |
|
44
|
|
|
*/ |
|
45
|
2 |
|
public function name(): ?string |
|
46
|
|
|
{ |
|
47
|
2 |
|
return $this->data['name'] ?? null; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Given name(s) or first name(s) of the End-User. |
|
52
|
|
|
* Note that in some cultures, people can have multiple given names; |
|
53
|
|
|
* all can be present, with the names being separated by space characters. |
|
54
|
|
|
* |
|
55
|
|
|
* @return string|null |
|
56
|
|
|
*/ |
|
57
|
1 |
|
public function givenName(): ?string |
|
58
|
|
|
{ |
|
59
|
1 |
|
return $this->data['given_name'] ?? null; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Surname(s) or last name(s) of the End-User. |
|
64
|
|
|
* Note that in some cultures, people can have multiple family names or no family name; |
|
65
|
|
|
* all can be present, with the names being separated by space characters. |
|
66
|
|
|
* |
|
67
|
|
|
* @return string|null |
|
68
|
|
|
*/ |
|
69
|
2 |
|
public function familyName(): ?string |
|
70
|
|
|
{ |
|
71
|
2 |
|
return $this->data['family_name'] ?? null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Middle name(s) of the End-User. |
|
76
|
|
|
* Note that in some cultures, people can have multiple middle names; |
|
77
|
|
|
* all can be present, with the names being separated by space characters. |
|
78
|
|
|
* Also note that in some cultures, middle names are not used. |
|
79
|
|
|
* |
|
80
|
|
|
* @return string|null |
|
81
|
|
|
*/ |
|
82
|
1 |
|
public function middleName(): ?string |
|
83
|
|
|
{ |
|
84
|
1 |
|
return $this->data['middle_name'] ?? null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Casual name of the End-User that may or may not be the same as the given_name. |
|
89
|
|
|
* For instance, a nickname value of Mike might be returned alongside a given_name value of Michael. |
|
90
|
|
|
* |
|
91
|
|
|
* @return string|null |
|
92
|
|
|
*/ |
|
93
|
1 |
|
public function nickname(): ?string |
|
94
|
|
|
{ |
|
95
|
1 |
|
return $this->data['nickname'] ?? null; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Shorthand name by which the End-User wishes to be referred to at the RP, such as janedoe or j.doe. |
|
100
|
|
|
* This value MAY be any valid JSON string including special characters such as @, /, or whitespace. |
|
101
|
|
|
* The RP MUST NOT rely upon this value being unique, as discussed in Section 5.7. |
|
102
|
|
|
* |
|
103
|
|
|
* @return string|null |
|
104
|
|
|
*/ |
|
105
|
1 |
|
public function preferredUsername(): ?string |
|
106
|
|
|
{ |
|
107
|
1 |
|
return $this->data['preferred_username'] ?? null; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* URL of the End-User's profile page. |
|
112
|
|
|
* The contents of this Web page SHOULD be about the End-User. |
|
113
|
|
|
* |
|
114
|
|
|
* @return string|null |
|
115
|
|
|
*/ |
|
116
|
1 |
|
public function profile(): ?string |
|
117
|
|
|
{ |
|
118
|
1 |
|
return $this->data['profile'] ?? null; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* URL of the End-User's profile picture. |
|
123
|
|
|
* This URL MUST refer to an image file (for example, a PNG, JPEG, or GIF image file), |
|
124
|
|
|
* rather than to a Web page containing an image. |
|
125
|
|
|
* Note that this URL SHOULD specifically reference a profile photo of the End-User suitable for displaying |
|
126
|
|
|
* when describing the End-User, rather than an arbitrary photo taken by the End-User. |
|
127
|
|
|
* |
|
128
|
|
|
* @return string|null |
|
129
|
|
|
*/ |
|
130
|
1 |
|
public function picture(): ?string |
|
131
|
|
|
{ |
|
132
|
1 |
|
return $this->data['picture'] ?? null; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* URL of the End-User's Web page or blog. |
|
137
|
|
|
* This Web page SHOULD contain information published by the End-User |
|
138
|
|
|
* or an organization that the End-User is affiliated with. |
|
139
|
|
|
* |
|
140
|
|
|
* @return string|null |
|
141
|
|
|
*/ |
|
142
|
1 |
|
public function website(): ?string |
|
143
|
|
|
{ |
|
144
|
1 |
|
return $this->data['website'] ?? null; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* End-User's preferred e-mail address. |
|
149
|
|
|
* Its value MUST conform to the RFC 5322 [RFC5322] addr-spec syntax. |
|
150
|
|
|
* The RP MUST NOT rely upon this value being unique, as discussed in Section 5.7. |
|
151
|
|
|
* |
|
152
|
|
|
* @return string|null |
|
153
|
|
|
*/ |
|
154
|
2 |
|
public function email(): ?string |
|
155
|
|
|
{ |
|
156
|
2 |
|
return $this->data['email'] ?? null; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* True if the End-User's e-mail address has been verified; otherwise false. |
|
161
|
|
|
* When this Claim Value is true, this means that the OP took affirmative steps to ensure |
|
162
|
|
|
* that this e-mail address was controlled by the End-User at the time the verification was performed. |
|
163
|
|
|
* The means by which an e-mail address is verified is context-specific, |
|
164
|
|
|
* and dependent upon the trust framework or contractual agreements within which the parties are operating. |
|
165
|
|
|
* |
|
166
|
|
|
* @return bool|null |
|
167
|
|
|
*/ |
|
168
|
1 |
|
public function emailVerified(): ?bool |
|
169
|
|
|
{ |
|
170
|
1 |
|
return $this->data['email_verified'] ?? null; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* End-User's gender. |
|
175
|
|
|
* Values defined by this specification are female and male. |
|
176
|
|
|
* Other values MAY be used when neither of the defined values are applicable. |
|
177
|
|
|
* |
|
178
|
|
|
* @return string|null |
|
179
|
|
|
*/ |
|
180
|
1 |
|
public function gender(): ?string |
|
181
|
|
|
{ |
|
182
|
1 |
|
return $this->data['gender'] ?? null; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* End-User's birthday, represented as an ISO 8601:2004 [ISO8601‑2004] YYYY-MM-DD format. |
|
187
|
|
|
* The year MAY be 0000, indicating that it is omitted. |
|
188
|
|
|
* To represent only the year, YYYY format is allowed. |
|
189
|
|
|
* Note that depending on the underlying platform's date related function, |
|
190
|
|
|
* providing just year can result in varying month and day, |
|
191
|
|
|
* so the implementers need to take this factor into account to correctly process the dates. |
|
192
|
|
|
* |
|
193
|
|
|
* @return string|null |
|
194
|
|
|
*/ |
|
195
|
1 |
|
public function birthdate(): ?string |
|
196
|
|
|
{ |
|
197
|
1 |
|
return $this->data['birthdate'] ?? null; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* String from zoneinfo [zoneinfo] time zone database representing the End-User's time zone. |
|
202
|
|
|
* For example, Europe/Paris or America/Los_Angeles. |
|
203
|
|
|
* |
|
204
|
|
|
* @return string|null |
|
205
|
|
|
*/ |
|
206
|
1 |
|
public function zoneinfo(): ?string |
|
207
|
|
|
{ |
|
208
|
1 |
|
return $this->data['zoneinfo'] ?? null; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* End-User's locale, represented as a BCP47 [RFC5646] language tag. |
|
213
|
|
|
* This is typically an ISO 639-1 Alpha-2 [ISO639‑1] language code in lowercase |
|
214
|
|
|
* and an ISO 3166-1 Alpha-2 [ISO3166‑1] country code in uppercase, separated by a dash. |
|
215
|
|
|
* For example, en-US or fr-CA. As a compatibility note, |
|
216
|
|
|
* some implementations have used an underscore as the separator rather than a dash, |
|
217
|
|
|
* for example, en_US; Relying Parties MAY choose to accept this locale syntax as well. |
|
218
|
|
|
* |
|
219
|
|
|
* @return string|null |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function locale(): ?string |
|
222
|
|
|
{ |
|
223
|
1 |
|
return $this->data['locale'] ?? null; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* End-User's preferred telephone number. |
|
228
|
|
|
* E.164 [E.164] is RECOMMENDED as the format of this Claim, for example, +1 (425) 555-1212 or +56 (2) 687 2400. |
|
229
|
|
|
* If the phone number contains an extension, it is RECOMMENDED that the extension be represented using |
|
230
|
|
|
* the RFC 3966 [RFC3966] extension syntax, for example, +1 (604) 555-1234;ext=5678. |
|
231
|
|
|
* |
|
232
|
|
|
* @return string|null |
|
233
|
|
|
*/ |
|
234
|
1 |
|
public function phoneNumber(): ?string |
|
235
|
|
|
{ |
|
236
|
1 |
|
return $this->data['phone_number'] ?? null; |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* True if the End-User's phone number has been verified; otherwise false. |
|
241
|
|
|
* When this Claim Value is true, this means that the OP took affirmative steps to ensure that this phone number |
|
242
|
|
|
* was controlled by the End-User at the time the verification was performed. |
|
243
|
|
|
* The means by which a phone number is verified is context-specific, |
|
244
|
|
|
* and dependent upon the trust framework or contractual agreements within which the parties are operating. |
|
245
|
|
|
* When true, the phone_number Claim MUST be in E.164 format |
|
246
|
|
|
* and any extensions MUST be represented in RFC 3966 format. |
|
247
|
|
|
* |
|
248
|
|
|
* @return bool|null |
|
249
|
|
|
*/ |
|
250
|
1 |
|
public function phoneNumberVerified(): ?bool |
|
251
|
|
|
{ |
|
252
|
1 |
|
return $this->data['phone_number_verified'] ?? null; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* End-User's preferred postal address. |
|
257
|
|
|
* The value of the address member is a JSON [RFC4627] structure containing |
|
258
|
|
|
* some or all of the members defined in Section 5.1.1. |
|
259
|
|
|
* |
|
260
|
|
|
* @return array|null |
|
261
|
|
|
*/ |
|
262
|
1 |
|
public function address(): ?array |
|
263
|
|
|
{ |
|
264
|
1 |
|
return $this->data['address'] ?? null; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Time the End-User's information was last updated. |
|
269
|
|
|
* Its value is a JSON number representing the number of seconds from 1970-01-01T0:0:0Z |
|
270
|
|
|
* as measured in UTC until the date/time. |
|
271
|
|
|
* |
|
272
|
|
|
* @return int|null |
|
273
|
|
|
*/ |
|
274
|
1 |
|
public function updatedAt(): ?int |
|
275
|
|
|
{ |
|
276
|
1 |
|
return $this->data['updated_at'] ?? null; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Get a claim value |
|
281
|
|
|
* |
|
282
|
|
|
* @param string $name The claim name |
|
283
|
|
|
* @param mixed $default The default value to return, when not defined on the response |
|
284
|
|
|
* |
|
285
|
|
|
* @return mixed |
|
286
|
|
|
*/ |
|
287
|
1 |
|
public function claim(string $name, $default = null) |
|
288
|
|
|
{ |
|
289
|
1 |
|
return $this->data[$name] ?? $default; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Get all claims of the userinfo |
|
294
|
|
|
* |
|
295
|
|
|
* @return array |
|
296
|
|
|
*/ |
|
297
|
|
|
public function claims(): array |
|
298
|
|
|
{ |
|
299
|
|
|
return $this->data; |
|
300
|
|
|
} |
|
301
|
|
|
} |
|
302
|
|
|
|