Browse Source

Discoverer can now remember per-server version and service information

(groundwork for attribute exchange support)
tags/0.5
Chris Smith 15 years ago
parent
commit
a1bc193dad
1 changed files with 71 additions and 19 deletions
  1. 71
    19
      discoverer.inc.php

+ 71
- 19
discoverer.inc.php View File

@@ -22,6 +22,41 @@
22 22
  * SOFTWARE.
23 23
  */
24 24
 
25
+class Server {
26
+
27
+ private $url = null;
28
+ private $version = 1;
29
+ private $services = array();
30
+
31
+ public function __construct($url, $version) {
32
+  $this->url = $url;
33
+  $this->version = $version;
34
+ }
35
+
36
+ public function getURL() {
37
+  return $this->url;
38
+ }
39
+
40
+ public function getVersion() {
41
+  return $this->version;
42
+ }
43
+
44
+ public function getServices() {
45
+  return $this->services;
46
+ }
47
+
48
+ public function addServices($services) {
49
+  foreach ($services as $service) {
50
+   $this->services[] = $service;
51
+  }
52
+ }
53
+
54
+ public function hasService($service) {
55
+  return array_search($service, $this->services) !== false;
56
+ }
57
+
58
+}
59
+
25 60
 class Discoverer {
26 61
 
27 62
  private $server = null;
@@ -41,7 +76,13 @@ class Discoverer {
41 76
  }
42 77
 
43 78
  public function hasServer($server) {
44
-  return array_search($server, $this->servers) !== false;
79
+  foreach ($this->servers as $match) {
80
+   if ($match->getURL() == $server) { 
81
+    return true;
82
+   }
83
+  }
84
+  
85
+  return false;
45 86
  }
46 87
 
47 88
  public function getDelegate() {
@@ -162,25 +203,36 @@ class Discoverer {
162 203
   // TODO: Better handling of namespaces
163 204
   $found = false;
164 205
   foreach ($sxml->XRD->Service as $service) {
165
-   if ((String) $service->Type == 'http://specs.openid.net/auth/2.0/server') {
166
-    $this->version = 2;
167
-    $this->server = (String) $service->URI;
168
-    $this->identity = $this->delegate = 'http://specs.openid.net/auth/2.0/identifier_select';
169
-    $this->servers[] = $this->server;
170
-    $found = true;
171
-   } else if ((String) $service->Type == 'http://specs.openid.net/auth/2.0/signon') {
172
-    $this->version = 2;
173
-    $this->server = (String) $service->URI;
174
-    $this->servers[] = $this->server;
175
-
176
-    if (isset($service->LocalID)) {
177
-     $this->identity = (String) $service->LocalID;
206
+   $services = array();
207
+   $server = null;
208
+
209
+   foreach ($service->Type as $type) {
210
+    if ((String) $type == 'http://specs.openid.net/auth/2.0/server') {
211
+     $this->version = 2;
212
+     $this->server = (String) $service->URI;
213
+     $this->identity = $this->delegate = 'http://specs.openid.net/auth/2.0/identifier_select';
214
+     $this->servers[] = $server = new Server($this->server, 2);
215
+     $found = true;
216
+    } else if ((String) $type == 'http://specs.openid.net/auth/2.0/signon') {
217
+     $this->version = 2;
218
+     $this->server = (String) $service->URI;
219
+     $this->servers[] = $server = new Server($this->server, 2);
220
+
221
+     if (isset($service->LocalID)) {
222
+      $this->identity = (String) $service->LocalID;
223
+     } else {
224
+      $this->identity = 'http://specs.openid.net/auth/2.0/identifier_select';
225
+     }
226
+     $this->delegate = 'http://specs.openid.net/auth/2.0/identifier_select';
227
+  
228
+     $found = true;
178 229
     } else {
179
-     $this->identity = 'http://specs.openid.net/auth/2.0/identifier_select';
230
+     $services[] = (String) $type;
180 231
     }
181
-    $this->delegate = 'http://specs.openid.net/auth/2.0/identifier_select';
232
+   }
182 233
 
183
-    $found = true;
234
+   if ($server != null) {
235
+    $server->addServices($services);
184 236
    }
185 237
   }
186 238
 
@@ -271,7 +323,7 @@ class Discoverer {
271 323
   if (isset($links['openid2.provider'])) {
272 324
    $this->version = 2;
273 325
    $this->server = $links['openid2.provider'];
274
-   $this->servers[] = $this->server;
326
+   $this->servers[] = new Server($this->server, 2);
275 327
 
276 328
    if (isset($links['openid2.local_id'])) {
277 329
     $this->delegate = $links['openid2.local_id'];
@@ -279,7 +331,7 @@ class Discoverer {
279 331
   } else if (isset($links['openid.server'])) {
280 332
    $this->version = 1;
281 333
    $this->server = $links['openid.server'];
282
-   $this->servers[] = $this->server;
334
+   $this->servers[] = new Server($this->server, 2);
283 335
 
284 336
    if (isset($links['openid.delegate'])) {
285 337
     $this->delegate = $links['openid.delegate'];

Loading…
Cancel
Save