|
@@ -61,38 +61,35 @@ class Server {
|
61
|
61
|
|
62
|
62
|
class Discoverer {
|
63
|
63
|
|
64
|
|
- private $server = null;
|
65
|
|
- private $servers = array();
|
66
|
|
- private $claimedId = '';
|
67
|
|
- private $identity = '';
|
68
|
|
- private $version = 1;
|
|
64
|
+ const ID_SELECT_URL = 'http://specs.openid.net/auth/2.0/identifier_select';
|
|
65
|
+
|
|
66
|
+ private $version; // OpenID 2 teminology || OpenID 1 terminology
|
|
67
|
+ // --------------------- || ----------------------
|
|
68
|
+ private $userSuppliedId; // User supplied ID || [Same as Claimed ID]
|
|
69
|
+ private $claimedId; // Claimed ID || Claimed ID
|
|
70
|
+ private $endpointUrl; // OP Endpoint URL || Identity Provider
|
|
71
|
+ private $opLocalId; // OP-local ID || Delegate
|
69
|
72
|
|
70
|
73
|
public function __construct($uri, $normalise = true) {
|
71
|
74
|
if ($uri !== null) {
|
72
|
|
- $this->discover($this->identity = ($normalise ? $this->normalise($uri) : $uri));
|
|
75
|
+ $this->discover($this->userSuppliedId = ($normalise ? $this->normalise($uri) : $uri));
|
73
|
76
|
}
|
74
|
77
|
}
|
75
|
78
|
|
76
|
|
- public function getServer() {
|
77
|
|
- return $this->server;
|
|
79
|
+ public function getEndpointUrl() {
|
|
80
|
+ return $this->endpointUrl;
|
78
|
81
|
}
|
79
|
82
|
|
80
|
|
- public function hasServer($server) {
|
81
|
|
- foreach ($this->servers as $match) {
|
82
|
|
- if ($match->getURL() == $server) {
|
83
|
|
- return true;
|
84
|
|
- }
|
85
|
|
- }
|
86
|
|
-
|
87
|
|
- return false;
|
|
83
|
+ public function getUserSuppliedId() {
|
|
84
|
+ return $this->userSuppliedId;
|
88
|
85
|
}
|
89
|
86
|
|
90
|
|
- public function getDelegate() {
|
|
87
|
+ public function getClaimedId() {
|
91
|
88
|
return $this->claimedId;
|
92
|
89
|
}
|
93
|
90
|
|
94
|
|
- public function getIdentity() {
|
95
|
|
- return $this->identity;
|
|
91
|
+ public function getOpLocalId() {
|
|
92
|
+ return $this->opLocalId;
|
96
|
93
|
}
|
97
|
94
|
|
98
|
95
|
public function getVersion() {
|
|
@@ -154,9 +151,6 @@ class Discoverer {
|
154
|
151
|
private function discover($uri) {
|
155
|
152
|
Logger::log('Performing discovery for %s', $uri);
|
156
|
153
|
|
157
|
|
- $this->claimedId = $uri;
|
158
|
|
- $this->server = null;
|
159
|
|
-
|
160
|
154
|
if (!$this->yadisDiscover($uri)) {
|
161
|
155
|
$this->htmlDiscover($uri);
|
162
|
156
|
}
|
|
@@ -220,7 +214,7 @@ class Discoverer {
|
220
|
214
|
if ((String) $type == 'http://specs.openid.net/auth/2.0/server') {
|
221
|
215
|
$this->version = 2;
|
222
|
216
|
$this->server = (String) $service->URI;
|
223
|
|
- $this->identity = 'http://specs.openid.net/auth/2.0/identifier_select';
|
|
217
|
+ $this->identity = self::ID_SELECT_URL;
|
224
|
218
|
$this->servers[] = $server = new Server($this->server, 2);
|
225
|
219
|
Logger::log('OpenID EP found (server). Server: %s, identity: %s, claimed id: %s', $this->server, $this->identity, $this->claimedId);
|
226
|
220
|
$found = true;
|
|
@@ -232,7 +226,7 @@ class Discoverer {
|
232
|
226
|
if (isset($service->LocalID)) {
|
233
|
227
|
$this->identity = (String) $service->LocalID;
|
234
|
228
|
} else {
|
235
|
|
- $this->identity = 'http://specs.openid.net/auth/2.0/identifier_select';
|
|
229
|
+ $this->identity = self::ID_SELECT_URL;
|
236
|
230
|
}
|
237
|
231
|
|
238
|
232
|
Logger::log('OpenID EP found (signon). Server: %s, identity: %s, claimed id: %s', $this->server, $this->identity, $this->claimedId);
|
|
@@ -272,25 +266,27 @@ class Discoverer {
|
272
|
266
|
return;
|
273
|
267
|
}
|
274
|
268
|
|
|
269
|
+ $this->claimedId = $uri;
|
|
270
|
+
|
275
|
271
|
$details = stream_get_meta_data($fh);
|
276
|
272
|
|
277
|
273
|
foreach ($details['wrapper_data'] as $line) {
|
278
|
274
|
if (preg_match('/^Location: (.*?)$/i', $line, $m)) {
|
279
|
275
|
if (strpos($m[1], '://') !== false) {
|
280
|
276
|
// Fully qualified URL
|
281
|
|
- $this->identity = $m[1];
|
|
277
|
+ $this->claimedId = $m[1];
|
282
|
278
|
} else if ($m[1][0] == '/') {
|
283
|
279
|
// Absolute URL
|
284
|
|
- $this->identity = preg_replace('#^(.*?://.*?)/.*$#', '\1', $this->identity) . $m[1];
|
|
280
|
+ $this->claimedId = preg_replace('#^(.*?://.*?)/.*$#', '\1', $this->claimedId) . $m[1];
|
285
|
281
|
} else {
|
286
|
282
|
// Relative URL
|
287
|
|
- $this->identity = preg_replace('#^(.*?://.*/).*?$#', '\1', $this->identity) . $m[1];
|
|
283
|
+ $this->claimedId = preg_replace('#^(.*?://.*/).*?$#', '\1', $this->claimedId) . $m[1];
|
288
|
284
|
}
|
289
|
285
|
}
|
290
|
|
- $this->identity = self::normalise($this->identity);
|
|
286
|
+ $this->claimedId = self::normalise($this->claimedId);
|
291
|
287
|
}
|
292
|
288
|
|
293
|
|
- Logger::log('Identity: %s', $this->identity);
|
|
289
|
+ Logger::log('Claimed identity: %s', $this->claimedId);
|
294
|
290
|
|
295
|
291
|
$data = '';
|
296
|
292
|
while (!feof($fh) && strpos($data, '</head>') === false) {
|
|
@@ -339,23 +335,30 @@ class Discoverer {
|
339
|
335
|
|
340
|
336
|
if (isset($links['openid2.provider'])) {
|
341
|
337
|
$this->version = 2;
|
342
|
|
- $this->server = $links['openid2.provider'];
|
343
|
|
- $this->servers[] = new Server($this->server, 2);
|
|
338
|
+ $this->endpointUrl = $links['openid2.provider'];
|
|
339
|
+ //$this->servers[] = new Server($this->server, 2);
|
344
|
340
|
|
345
|
341
|
if (isset($links['openid2.local_id'])) {
|
346
|
|
- $this->identity = $links['openid2.local_id'];
|
|
342
|
+ $this->claimedId = $this->userSuppliedId;
|
|
343
|
+ $this->opLocalId = $links['openid2.local_id'];
|
|
344
|
+ } else {
|
|
345
|
+ $this->claimedId = self::ID_SELECT_URL;
|
|
346
|
+ $this->opLocalId = self::ID_SELECT_URL;
|
347
|
347
|
}
|
348
|
|
- Logger::log('OpenID EP found. Server: %s, identity: %s, claimed id: %s', $this->server, $this->identity, $this->claimedId);
|
|
348
|
+
|
|
349
|
+ Logger::log('OpenID EP found. End point: %s, claimed id: %s, op local id: %s', $this->endpointUrl, $this->claimedId, $this->opLocalId);
|
349
|
350
|
} else if (isset($links['openid.server'])) {
|
350
|
351
|
$this->version = 1;
|
351
|
|
- $this->server = $links['openid.server'];
|
352
|
|
- $this->servers[] = new Server($this->server, 2);
|
|
352
|
+ $this->endpointUrl = $links['openid.server'];
|
|
353
|
+ //$this->servers[] = new Server($this->server, 2);
|
|
354
|
+
|
|
355
|
+ $this->claimedId = $this->userSuppliedId;
|
353
|
356
|
|
354
|
357
|
if (isset($links['openid.delegate'])) {
|
355
|
|
- $this->claimedId = $this->identity;
|
356
|
|
- $this->identity = $links['openid.delegate'];
|
|
358
|
+ $this->opLocalId = $links['openid.delegate'];
|
357
|
359
|
}
|
358
|
|
- Logger::log('OpenID EP found. Server: %s, identity: %s, claimed id: %s', $this->server, $this->identity, $this->claimedId);
|
|
360
|
+
|
|
361
|
+ Logger::log('OpenID EP found. End point: %s, claimed id: %s, op local id: %s', $this->endpointUrl, $this->claimedId, $this->opLocalId);
|
359
|
362
|
}
|
360
|
363
|
}
|
361
|
364
|
|