diff options
author | tailor <cygnus@janrain.com> | 2007-03-19 18:17:37 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2007-03-19 18:17:37 +0000 |
commit | 0e7262c6e711b9cf17f84bc75bfbb73b2a1168a9 (patch) | |
tree | 5477fa1f708662a6f132f60199c10c67a38260bf /examples/server/lib | |
parent | 874031d1e516c1061c0355819205d4ece65c3dd1 (diff) | |
download | php-openid-0e7262c6e711b9cf17f84bc75bfbb73b2a1168a9.zip php-openid-0e7262c6e711b9cf17f84bc75bfbb73b2a1168a9.tar.gz php-openid-0e7262c6e711b9cf17f84bc75bfbb73b2a1168a9.tar.bz2 |
[project @ Update example server to accept arbitrary logins (to make it easier to use and configure)]
Diffstat (limited to 'examples/server/lib')
-rw-r--r-- | examples/server/lib/actions.php | 15 | ||||
-rw-r--r-- | examples/server/lib/common.php | 2 | ||||
-rw-r--r-- | examples/server/lib/render.php | 5 | ||||
-rw-r--r-- | examples/server/lib/render/idpage.php | 26 | ||||
-rw-r--r-- | examples/server/lib/render/login.php | 4 | ||||
-rw-r--r-- | examples/server/lib/render/trust.php | 4 | ||||
-rw-r--r-- | examples/server/lib/session.php | 37 |
7 files changed, 61 insertions, 32 deletions
diff --git a/examples/server/lib/actions.php b/examples/server/lib/actions.php index 5e255e2..f38637f 100644 --- a/examples/server/lib/actions.php +++ b/examples/server/lib/actions.php @@ -6,6 +6,7 @@ require_once "lib/render.php"; require_once "lib/render/login.php"; require_once "lib/render/sites.php"; +require_once "lib/render/idpage.php"; require_once "Auth/OpenID.php"; @@ -88,17 +89,8 @@ function login_checkInput($input) if (!isset($input['openid_url'])) { $errors[] = 'Enter an OpenID URL to continue'; } - if (!isset($input['password'])) { - $errors[] = 'Enter a password to continue'; - } if (count($errors) == 0) { $openid_url = $input['openid_url']; - $openid_url = Auth_OpenID::normalizeUrl($openid_url); - $password = $input['password']; - if (!checkLogin($openid_url, $password)) { - $errors[] = 'The entered password does not match the ' . - 'entered identity URL.'; - } } return array($errors, $openid_url); } @@ -166,4 +158,9 @@ function action_sites() return sites_render($sites); } +function action_idpage() +{ + return idpage_render(getLoggedInUser()); +} + ?>
\ No newline at end of file diff --git a/examples/server/lib/common.php b/examples/server/lib/common.php index 4bc1dac..147d74a 100644 --- a/examples/server/lib/common.php +++ b/examples/server/lib/common.php @@ -32,7 +32,7 @@ function doAuth($info, $trusted=null, $fail_cancels=false) $user = getLoggedInUser(); setRequestInfo($info); - if ($req_url != $user) { + if ($req_url != idURL($user)) { return login_render(array(), $req_url, $req_url); } diff --git a/examples/server/lib/render.php b/examples/server/lib/render.php index f607f90..502e08c 100644 --- a/examples/server/lib/render.php +++ b/examples/server/lib/render.php @@ -15,7 +15,7 @@ define('page_template', </body> </html>'); -define('logged_in_pat', 'You are logged in as %s.'); +define('logged_in_pat', 'You are logged in as %s (URL: %s)'); /** * HTTP response line contstants @@ -88,7 +88,8 @@ function page_render($body, $user, $title, $h1=null, $login=false) $h1 = $h1 ? $h1 : $title; if ($user) { - $msg = sprintf(logged_in_pat, link_render($user)); + $msg = sprintf(logged_in_pat, link_render($user), + link_render(idURL($user))); $nav = array('logout' => 'Log Out', 'sites' => 'Remembered Sites', ); diff --git a/examples/server/lib/render/idpage.php b/examples/server/lib/render/idpage.php new file mode 100644 index 0000000..103ec3c --- /dev/null +++ b/examples/server/lib/render/idpage.php @@ -0,0 +1,26 @@ +<?php + +require_once "lib/session.php"; +require_once "lib/render.php"; + +define('idpage_pat', + '<html> +<head> + <link rel="openid2.provider openid.server" href="%s"/> +</head> +<body> + This is the identity page for %s. +</body> +</html>'); + +define('login_needed_pat', + 'You must be logged in as %s to approve this request.'); + +function idpage_render($identity) +{ + $esc_identity = htmlspecialchars($identity, ENT_QUOTES); + $body = sprintf(idpage_pat, buildURL(), $esc_identity); + return array(array(), $body); +} + +?>
\ No newline at end of file diff --git a/examples/server/lib/render/login.php b/examples/server/lib/render/login.php index 9e8f370..19a242a 100644 --- a/examples/server/lib/render/login.php +++ b/examples/server/lib/render/login.php @@ -18,10 +18,6 @@ define('login_form_pat', value="%s" id="openid_url" /></td> </tr> <tr> - <th><label for="password">Password:</label></th> - <td><input type="password" name="password" id="password" /></td> - </tr> - <tr> <td colspan="2"> <input type="submit" value="Log in" /> <input type="submit" name="cancel" value="Cancel" /> diff --git a/examples/server/lib/render/trust.php b/examples/server/lib/render/trust.php index 60d01d0..9acfae7 100644 --- a/examples/server/lib/render/trust.php +++ b/examples/server/lib/render/trust.php @@ -5,7 +5,7 @@ require_once "lib/render.php"; define('trust_form_pat', '<div class="form"> - <p>Do you wish to confirm your identity URL (<code>%s</code>) with <code>%s</code>?</p> + <p>Do you wish to confirm your identity (<code>%s</code>) with <code>%s</code>?</p> <form method="post" action="%s"> <input type="checkbox" name="remember" value="on" id="remember"><label for="remember">Remember this decision</label> @@ -19,7 +19,7 @@ define('trust_form_pat', function trust_render($info) { $current_user = getLoggedInUser(); - $lnk = link_render($current_user); + $lnk = link_render(idURL($current_user)); $trust_root = htmlspecialchars($info->trust_root); $trust_url = buildURL('trust', true); $form = sprintf(trust_form_pat, $lnk, $trust_root, $trust_url); diff --git a/examples/server/lib/session.php b/examples/server/lib/session.php index e11fd64..1a51d79 100644 --- a/examples/server/lib/session.php +++ b/examples/server/lib/session.php @@ -82,7 +82,8 @@ function getServer() { static $server = null; if (!isset($server)) { - $server =& new Auth_OpenID_Server(getOpenIDStore()); + $server =& new Auth_OpenID_Server(getOpenIDStore(), + getServerURL()); } return $server; } @@ -116,19 +117,6 @@ function hashPassword($password) } /** - * Check the user's login information - */ -function checkLogin($openid_url, $password) -{ - // from config.php - global $openid_users; - $hash = hashPassword($password); - - return isset($openid_users[$openid_url]) - && $hash == $openid_users[$openid_url]; -} - -/** * Get the openid_url out of the cookie * * @return mixed $openid_url The URL that was stored in the cookie or @@ -202,4 +190,25 @@ function getSreg($identity) } +function idURL($identity) +{ + return buildURL('idpage') . "?user=" . $identity; +} + +function idFromURL($url) +{ + if (strpos($url, 'idpage') === false) { + return null; + } + + $parsed = parse_url($url); + + $q = $parsed['query']; + + $parts = array(); + parse_str($q, $parts); + + return @$parts['user']; +} + ?>
\ No newline at end of file |