XRDS for ID provider and user
authorAymeric Augustin <aymeric.augustin@m4x.org>
Sat, 25 Oct 2008 12:51:31 +0000 (14:51 +0200)
committerAymeric Augustin <aymeric.augustin@m4x.org>
Sat, 25 Oct 2008 21:37:14 +0000 (23:37 +0200)
Change path to library to simplify includes

.gitignore
Makefile
modules/openid.php
modules/openid/openid.inc.php [new file with mode: 0644]
templates/openid/idp_xrds.tpl [new file with mode: 0644]
templates/openid/openid.tpl
templates/openid/user_xrds.tpl [new file with mode: 0644]

index b26965f..d183bb6 100644 (file)
@@ -1,4 +1,4 @@
 /wiki
 /spool
-/include/openid
+/include/Auth
 .*.sw?
index c2fb537..e297744 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -116,10 +116,10 @@ openid: get-openid
 
 # There is no obvious way to automatically use the latest version
 get-openid:
-       @if ! test -d include/openid; then                                \
+       @if ! test -d include/Auth; then                                  \
            wget http://openidenabled.com/files/php-openid/packages/php-openid-2.1.2.tar.bz2; \
            tar -xjf php-openid-2.1.2.tar.bz2;                            \
-           mv php-openid-2.1.2/Auth include/openid;                      \
+           mv php-openid-2.1.2/Auth include/;                            \
            rm php-openid-2.1.2.tar.bz2;                                  \
            rm -r php-openid-2.1.2;                                       \
        fi
index 7a8ad83..c05c0bc 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-
-
 class OpenidModule extends PLModule
 {
     function handlers()
     {
         return array(
             'openid'    => $this->make_hook('openid', AUTH_PUBLIC),
+            'openid/idp_xrds'   => $this->make_hook('idp_xrds', AUTH_PUBLIC),
+            'openid/user_xrds'  => $this->make_hook('user_xrds', AUTH_PUBLIC),
+            'openid/trust'  => $this->make_hook('trust', AUTH_PUBLIC),
         );
     }
 
+    function init_openid()
+    {
+        require_once 'Auth/OpenID.php';
+        $this->load('openid.inc.php');
+    }
+
     function handler_openid(&$page, $x = null)
     {
+        global $globals;
+
         // Determines the user whose openid we are going to display
         if (is_null($x)) {
             return PL_NOT_FOUND;
@@ -42,6 +51,10 @@ class OpenidModule extends PLModule
             return PL_NOT_FOUND;
         }
 
+        // Include X-XRDS-Location response-header for Yadis discovery
+        $user_xrds = $globals->baseurl . 'openid/user_xrds/' . $login->hruid;
+        header('X-XRDS-Location: ' . $user_xrds);
+
         // Select template
         $page->changeTpl('openid/openid.tpl');
 
@@ -56,8 +69,40 @@ class OpenidModule extends PLModule
 
         // Adds the global user property array to the display.
         $page->assign_by_ref('user', $login);
+    }
+
+    function handler_idp_xrds(&$page)
+    {
+        global $globals;
+
+        // Load constants
+        require_once "Auth/OpenID/Discover.php";
+
+        // Set XRDS content-type and template
+        header('Content-type: application/xrds+xml');
+        $page->changeTpl('openid/idp_xrds.tpl', NO_SKIN);
+
+        // Set variables
+        $page->changeTpl('openid/idp_xrds.tpl', NO_SKIN);
+        $page->assign('type', Auth_OpenID_TYPE_2_0_IDP);
+        $page->assign('uri', $globals->baseurl . '/openid');
+    }
+
+    function handler_user_xrds(&$page, $x = null)
+    {
+        global $globals;
+
+        // Load constants
+        require_once "Auth/OpenID/Discover.php";
 
+        // Set XRDS content-type and template
+        header('Content-type: application/xrds+xml');
+        $page->changeTpl('openid/user_xrds.tpl', NO_SKIN);
 
+        // Set variables
+        $page->assign('type1', Auth_OpenID_TYPE_2_0);
+        $page->assign('type2', Auth_OpenID_TYPE_1_1);
+        $page->assign('uri', $globals->baseurl . '/openid');
     }
 
 }
diff --git a/modules/openid/openid.inc.php b/modules/openid/openid.inc.php
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/templates/openid/idp_xrds.tpl b/templates/openid/idp_xrds.tpl
new file mode 100644 (file)
index 0000000..ae6c214
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+    xmlns:xrds="xri://$xrds"
+    xmlns="xri://$xrd*($v*2.0)">
+  <XRD>
+    <Service priority="0">
+      <Type>{$type}</Type>
+      <URI>{$uri}</URI>
+    </Service>
+  </XRD>
+</xrds:XRDS>
\ No newline at end of file
index acb96d4..75ab15a 100644 (file)
@@ -22,7 +22,6 @@
 
 <h1>Page d'identité OpenId de {$user->fullName()}</h1>
 
-
 <p>OpenID est un système d'authentification décentralisé. Cette page permet 
 à des sites web tiers d'identifier {$user->displayName()}, grâce à son compte 
 Polytechnique.org.<p>
diff --git a/templates/openid/user_xrds.tpl b/templates/openid/user_xrds.tpl
new file mode 100644 (file)
index 0000000..44c03a9
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xrds:XRDS
+    xmlns:xrds="xri://$xrds"
+    xmlns="xri://$xrd*($v*2.0)">
+  <XRD>
+    <Service priority="0">
+      <Type>{$type2}</Type>
+      <Type>{$type1}</Type>
+      <URI>{$uri}</URI>
+    </Service>
+  </XRD>
+</xrds:XRDS>
\ No newline at end of file