$this->make_hook('openid', AUTH_PUBLIC), 'openid/trust' => $this->make_hook('trust', AUTH_COOKIE), 'openid/idp_xrds' => $this->make_hook('idp_xrds', AUTH_PUBLIC), 'openid/user_xrds' => $this->make_hook('user_xrds', AUTH_PUBLIC), ); } function handler_openid(&$page, $x = null) { $this->load('openid.inc.php'); $user = get_user($x); // Spec ยง4.1.2: if "openid.mode" is absent, whe SHOULD assume that // the request is not an OpenId message // Thus, we try to render the discovery page if (!array_key_exists('openid_mode', $_REQUEST)) { return $this->render_discovery_page($page, $user); } // Create a server and decode the request $server = init_openid_server(); $request = $server->decodeRequest(); // This request requires user interaction if (in_array($request->mode, array('checkid_immediate', 'checkid_setup'))) { // Each user has only one identity to choose from // So we can make automatically the identity selection if ($request->idSelect()) { $request->identity = get_user_openid_url($user); } // If we still don't have an identifier (used or desired), give up if (!$request->identity) { $this->render_no_identifier_page($page, $request); return; } // We always require confirmation before sending information // to third-party websites if ($request->immediate) { $response =& $request->answer(false); } else { // Save request in session and jump to confirmation page S::set('openid_request', serialize($request)); pl_redirect('openid/trust'); return; } // Other requests can be automatically handled by the server } else { $response =& $server->handleRequest($request); } // Render response $webresponse =& $server->encodeResponse($response); $this->render_openid_response($webresponse); } function handler_trust(&$page, $x = null) { $this->load('openid.inc.php'); // Recover request in session $request = S::v('openid_request'); if (is_null($request)) { // There is no authentication information, something went wrong pl_redirect('/'); return; } else { // Unserialize the request require_once 'Auth/OpenID/Server.php'; $request = unserialize($request); } $server = init_openid_server(); $user = S::user(); // Check that the identity matches the user currently logged in if ($request->identity != get_user_openid_url($user)) { $response =& $request->answer(false); $webresponse =& $server->encodeResponse($response); $this->render_openid_response($webresponse); return; } // Prepare Simple Registration response fields require_once 'Auth/OpenID/SReg.php'; $sreg_request = Auth_OpenID_SRegRequest::fromOpenIDRequest($request); $sreg_response = Auth_OpenID_SRegResponse::extractResponse($sreg_request, get_sreg_data($user)); // Ask the user for confirmation if ($_SERVER['REQUEST_METHOD'] != 'POST') { $page->changeTpl('openid/trust.tpl'); $page->assign('relying_party', $request->trust_root); $page->assign_by_ref('sreg_data', $sreg_response->data); return; } // At this point $_SERVER['REQUEST_METHOD'] == 'POST' // Answer to the Relying Party based on the user's choice if (isset($_POST['trust'])) { S::kill('openid_request'); $response =& $request->answer(true, null, $request->identity); // Add the simple registration response values to the OpenID // response message. $sreg_response->toMessage($response->fields); } else { // !isset($_POST['trust']) S::kill('openid_request'); $response =& $request->answer(false); } // Generate a response to send to the user agent. $webresponse =& $server->encodeResponse($response); $this->render_openid_response($webresponse); } function handler_idp_xrds(&$page) { // Load constants $this->load('openid.inc.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', get_openid_url()); } function handler_user_xrds(&$page, $x = null) { // Load constants $this->load('openid.inc.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', get_openid_url()); } //--------------------------------------------------------------------// function render_discovery_page(&$page, $user) { // Show the documentation if this is not the OpenId page of an user if (is_null($user)) { pl_redirect('Xorg/OpenId'); } // Include X-XRDS-Location response-header for Yadis discovery header('X-XRDS-Location: ' . get_user_xrds_url($user)); // Select template $page->changeTpl('openid/openid.tpl'); // Sets the title of the html page. $page->setTitle($user->fullName()); // Sets the tags for HTML-Based Discovery $page->addLink('openid.server openid2.provider', get_openid_url()); $page->addLink('openid.delegate openid2.local_id', $user->hruid); // Adds the global user property array to the display. $page->assign_by_ref('user', $user); return; } function render_no_identifier_page($page, $request) { // Select template $page->changeTpl('openid/no_identifier.tpl'); } function render_openid_response($webresponse) { // Send HTTP response code if ($webresponse->code != AUTH_OPENID_HTTP_OK) { header(sprintf("HTTP/1.1 %d ", $webresponse->code), true, $webresponse->code); } // Send headers foreach ($webresponse->headers as $k => $v) { header("$k: $v"); } header('Connection: close'); // Send body print $webresponse->body; exit; } } // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: ?>