From b69727b412cae8449a78dee9ec79ddc70aab985f Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 25 Oct 2008 14:51:31 +0200 Subject: [PATCH] XRDS for ID provider and user Change path to library to simplify includes --- .gitignore | 2 +- Makefile | 4 ++-- modules/openid.php | 49 ++++++++++++++++++++++++++++++++++++++++-- modules/openid/openid.inc.php | 0 templates/openid/idp_xrds.tpl | 11 ++++++++++ templates/openid/openid.tpl | 1 - templates/openid/user_xrds.tpl | 12 +++++++++++ 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 modules/openid/openid.inc.php create mode 100644 templates/openid/idp_xrds.tpl create mode 100644 templates/openid/user_xrds.tpl diff --git a/.gitignore b/.gitignore index b26965f..d183bb6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /wiki /spool -/include/openid +/include/Auth .*.sw? diff --git a/Makefile b/Makefile index c2fb537..e297744 100644 --- 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 diff --git a/modules/openid.php b/modules/openid.php index 7a8ad83..c05c0bc 100644 --- a/modules/openid.php +++ b/modules/openid.php @@ -19,19 +19,28 @@ * 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 index 0000000..e69de29 diff --git a/templates/openid/idp_xrds.tpl b/templates/openid/idp_xrds.tpl new file mode 100644 index 0000000..ae6c214 --- /dev/null +++ b/templates/openid/idp_xrds.tpl @@ -0,0 +1,11 @@ + + + + + {$type} + {$uri} + + + \ No newline at end of file diff --git a/templates/openid/openid.tpl b/templates/openid/openid.tpl index acb96d4..75ab15a 100644 --- a/templates/openid/openid.tpl +++ b/templates/openid/openid.tpl @@ -22,7 +22,6 @@

Page d'identité OpenId de {$user->fullName()}

-

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.

diff --git a/templates/openid/user_xrds.tpl b/templates/openid/user_xrds.tpl new file mode 100644 index 0000000..44c03a9 --- /dev/null +++ b/templates/openid/user_xrds.tpl @@ -0,0 +1,12 @@ + + + + + {$type2} + {$type1} + {$uri} + + + \ No newline at end of file -- 2.1.4