Browse Source

Ensure trust_root is always below return_to URL

Make javascript example allow the library to determine trust_root itself
tags/0.5
Chris Smith 15 years ago
parent
commit
35095d4a92
4 changed files with 16 additions and 11 deletions
  1. 1
    0
      .gitignore
  2. 0
    1
      examples/javascript/iframe.php
  3. 0
    2
      examples/javascript/index.php
  4. 15
    8
      urlbuilder.inc.php

+ 1
- 0
.gitignore View File

1
+/keycache.php

+ 0
- 1
examples/javascript/iframe.php View File

24
 
24
 
25
  session_start();
25
  session_start();
26
 
26
 
27
- define('OPENID_TRUSTROOT', $_SESSION['trustroot']);
28
  define('OPENID_IMMEDIATE', true);
27
  define('OPENID_IMMEDIATE', true);
29
 
28
 
30
  if (isset($_GET['openid_id'])) {
29
  if (isset($_GET['openid_id'])) {

+ 0
- 2
examples/javascript/index.php View File

32
   exit;
32
   exit;
33
  }
33
  }
34
 
34
 
35
- $_SESSION['trustroot'] = URLBuilder::getCurrentURL();
36
-
37
  if (isset($_POST['openid_url']) || isset($_REQUEST['openid_mode'])) {
35
  if (isset($_POST['openid_url']) || isset($_REQUEST['openid_mode'])) {
38
   // Proxy for non-JS users
36
   // Proxy for non-JS users
39
 
37
 

+ 15
- 8
urlbuilder.inc.php View File

56
   public static function buildRequest($type, $base, $delegate, $identity, $returnURL, $handle) {
56
   public static function buildRequest($type, $base, $delegate, $identity, $returnURL, $handle) {
57
    $args = array(
57
    $args = array(
58
     'openid.ns' => self::NAMESPACE,
58
     'openid.ns' => self::NAMESPACE,
59
-	'openid.mode' => 'checkid_' . $type,
60
-	'openid.identity' => $delegate,
61
-	'openid.claimed_id' => $identity,
62
-	'openid.trust_root' => self::getTrustRoot(),
63
-	'openid.return_to' => self::addArguments($returnURL,
59
+    'openid.mode' => 'checkid_' . $type,
60
+    'openid.identity' => $delegate,
61
+    'openid.claimed_id' => $identity,
62
+    'openid.trust_root' => self::getTrustRoot($returnURL),
63
+    'openid.return_to' => self::addArguments($returnURL,
64
 		array('openid.nonce' => $_SESSION['openid']['nonce']))
64
 		array('openid.nonce' => $_SESSION['openid']['nonce']))
65
    );
65
    );
66
 
66
 
73
    return self::addArguments($base, $args);
73
    return self::addArguments($base, $args);
74
   }
74
   }
75
 
75
 
76
-  private static function getTrustRoot() {
76
+  private static function getTrustRoot($base = null) {
77
    if (defined('OPENID_TRUSTROOT')) {
77
    if (defined('OPENID_TRUSTROOT')) {
78
     return OPENID_TRUSTROOT;
78
     return OPENID_TRUSTROOT;
79
-   } else {
80
-    return self::getCurrentURL();
81
    }
79
    }
80
+
81
+   $curr = self::getCurrentURL();
82
+   $root = $base == null ? $curr : $base;
83
+
84
+   while (substr($curr, 0, strlen($root)) != $root) {
85
+    $root = dirname($root) . '/';
86
+   }
87
+
88
+   return $root; 
82
   }
89
   }
83
 
90
 
84
   private static function addSRegArgs(&$args) {
91
   private static function addSRegArgs(&$args) {

Loading…
Cancel
Save