|
@@ -165,6 +165,10 @@ class Discoverer {
|
165
|
165
|
private function yadisDiscover($uri, $allowLocation = true) {
|
166
|
166
|
Logger::log('Attempting Yadis discovery on %s', $uri);
|
167
|
167
|
|
|
168
|
+ if ($allowLocation) {
|
|
169
|
+ $this->claimedId = $uri;
|
|
170
|
+ }
|
|
171
|
+
|
168
|
172
|
$ctx = stream_context_create(array(
|
169
|
173
|
'http' => array(
|
170
|
174
|
'header' => "Accept: application/xrds+xml\r\n",
|
|
@@ -190,13 +194,18 @@ class Discoverer {
|
190
|
194
|
foreach ($details['wrapper_data'] as $line) {
|
191
|
195
|
if ($allowLocation && preg_match('/^X-XRDS-Location:\s*(.*?)$/i', $line, $m)) {
|
192
|
196
|
// TODO: Allow relative URLs?
|
|
197
|
+ $this->handleRedirects($details);
|
193
|
198
|
return $this->yadisDiscover($m[1], false);
|
194
|
199
|
} else if (preg_match('#^Content-type:\s*application/xrds\+xml(;.*?)?$#i', $line)) {
|
|
200
|
+ $this->handleRedirects($details);
|
195
|
201
|
return $this->parseYadis($data);
|
196
|
202
|
}
|
197
|
203
|
}
|
198
|
204
|
|
199
|
|
- return $this->parseYadisHTML($data);
|
|
205
|
+ if (($url = $this->parseYadisHTML($data)) !== false) {
|
|
206
|
+ $this->handleRedirects($details);
|
|
207
|
+ return $this->yadisDiscover($url, false);
|
|
208
|
+ }
|
200
|
209
|
}
|
201
|
210
|
|
202
|
211
|
private function parseYadis($data) {
|
|
@@ -230,7 +239,6 @@ class Discoverer {
|
230
|
239
|
|
231
|
240
|
if (isset($service->LocalID)) {
|
232
|
241
|
$this->opLocalId = (String) $service->LocalID;
|
233
|
|
- $this->claimedId = $this->userSuppliedId;
|
234
|
242
|
} else {
|
235
|
243
|
$this->opLocalId = self::ID_SELECT_URL;
|
236
|
244
|
$this->claimedId = self::ID_SELECT_URL;
|
|
@@ -258,7 +266,7 @@ class Discoverer {
|
258
|
266
|
if (isset($meta['x-xrds-location'])) {
|
259
|
267
|
Logger::log('Found XRDS meta tag: %s', $meta['x-xrds-location']);
|
260
|
268
|
// TODO: Allow relative URLs?
|
261
|
|
- return $this->yadisDiscover($meta['x-xrds-location'], false);
|
|
269
|
+ return $meta['x-xrds-location'];
|
262
|
270
|
}
|
263
|
271
|
|
264
|
272
|
return false;
|
|
@@ -278,32 +286,39 @@ class Discoverer {
|
278
|
286
|
|
279
|
287
|
$details = stream_get_meta_data($fh);
|
280
|
288
|
|
|
289
|
+ $this->handleRedirects($details);
|
|
290
|
+
|
|
291
|
+ Logger::log('Claimed identity: %s', $this->claimedId);
|
|
292
|
+
|
|
293
|
+ $data = '';
|
|
294
|
+ while (!feof($fh) && strpos($data, '</head>') === false) {
|
|
295
|
+ $data .= fgets($fh);
|
|
296
|
+ }
|
|
297
|
+
|
|
298
|
+ fclose($fh);
|
|
299
|
+
|
|
300
|
+ $this->parseHtml($data);
|
|
301
|
+ }
|
|
302
|
+
|
|
303
|
+ protected function handleRedirects($details) {
|
281
|
304
|
foreach ($details['wrapper_data'] as $line) {
|
282
|
305
|
if (preg_match('/^Location: (.*?)$/i', $line, $m)) {
|
283
|
306
|
if (strpos($m[1], '://') !== false) {
|
284
|
307
|
// Fully qualified URL
|
285
|
308
|
$this->claimedId = $m[1];
|
|
309
|
+ Logger::log('Redirection (full qualified) to ' . $m[1]);
|
286
|
310
|
} else if ($m[1][0] == '/') {
|
287
|
311
|
// Absolute URL
|
288
|
312
|
$this->claimedId = preg_replace('#^(.*?://.*?)/.*$#', '\1', $this->claimedId) . $m[1];
|
|
313
|
+ Logger::log('Redirection (absolute) to ' . $m[1] . ': ' . $this->claimedId);
|
289
|
314
|
} else {
|
290
|
315
|
// Relative URL
|
291
|
316
|
$this->claimedId = preg_replace('#^(.*?://.*/).*?$#', '\1', $this->claimedId) . $m[1];
|
|
317
|
+ Logger::log('Redirection (relative) to ' . $m[1] . ': ' . $this->claimedId);
|
292
|
318
|
}
|
293
|
319
|
}
|
294
|
320
|
$this->claimedId = self::normalise($this->claimedId);
|
295
|
321
|
}
|
296
|
|
-
|
297
|
|
- Logger::log('Claimed identity: %s', $this->claimedId);
|
298
|
|
-
|
299
|
|
- $data = '';
|
300
|
|
- while (!feof($fh) && strpos($data, '</head>') === false) {
|
301
|
|
- $data .= fgets($fh);
|
302
|
|
- }
|
303
|
|
-
|
304
|
|
- fclose($fh);
|
305
|
|
-
|
306
|
|
- $this->parseHtml($data);
|
307
|
322
|
}
|
308
|
323
|
|
309
|
324
|
protected static function getLinks($data) {
|
|
@@ -355,6 +370,7 @@ class Discoverer {
|
355
|
370
|
$this->claimedId = $this->userSuppliedId;
|
356
|
371
|
$this->opLocalId = isset($links['openid2.local_id']) ? $links['openid2.local_id'] : $this->claimedId;
|
357
|
372
|
|
|
373
|
+ $this->servers[$this->endpointUrl] = $server = new Server($this->endpointUrl, $this->version);
|
358
|
374
|
Logger::log('OpenID EP found. End point: %s, claimed id: %s, op local id: %s', $this->endpointUrl, $this->claimedId, $this->opLocalId);
|
359
|
375
|
} else if (isset($links['openid.server'])) {
|
360
|
376
|
$this->version = 1;
|
|
@@ -367,6 +383,7 @@ class Discoverer {
|
367
|
383
|
$this->opLocalId = $links['openid.delegate'];
|
368
|
384
|
}
|
369
|
385
|
|
|
386
|
+ $this->servers[$this->endpointUrl] = $server = new Server($this->endpointUrl, $this->version);
|
370
|
387
|
Logger::log('OpenID EP found. End point: %s, claimed id: %s, op local id: %s', $this->endpointUrl, $this->claimedId, $this->opLocalId);
|
371
|
388
|
}
|
372
|
389
|
}
|