9 * @author Bill Shupp <hostmaster@shupp.org>
10 * @copyright 2009 Bill Shupp
11 * @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
12 * @link http://github.com/shupp/openid
15 // A tool for testing Relying Party functionality
17 __DIR__ . '/../../src/'
18 . PATH_SEPARATOR . get_include_path()
21 require_once 'www-header.php';
22 require_once 'openid/config.php';
25 if (isset($_REQUEST['logout'])) {
28 $redirect = 'http://' . $_SERVER['HTTP_HOST'];
29 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
33 if (!count($_GET) && !count($_POST)) {
34 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/login";
35 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
39 // Hackaround Non-Javascript Login Page
40 if (!count($_POST) && isset($_GET['start'])) {
44 if (isset($_POST['identifier'])) {
45 $identifier = $_POST['identifier'];
46 } else if (isset($_SESSION['identifier'])) {
47 $identifier = $_SESSION['identifier'];
53 $o = new OpenID_RelyingParty($returnTo, $realm, $identifier);
54 } catch (OpenID_Exception $e) {
55 $contents = "<div class='openid_results'>\n";
56 $contents .= "<pre>" . $e->getMessage() . "</pre>\n";
57 $contents .= "</div class='openid_results'>";
58 include_once 'openid/wrapper.php';
62 if (!empty($_POST['disable_associations'])
63 || !empty($_SESSION['disable_associations'])) {
65 $o->disableAssociations();
66 $_SESSION['disable_associations'] = true;
69 $log = new OpenID_Observer_Log;
72 if (isset($_POST['start'])) {
74 $_SESSION['identifier'] = $identifier;
76 $authRequest = $o->prepare();
77 } catch (OpenID_Exception $e) {
78 $contents = "<div class='openid_results'>\n";
79 $contents .= "<pre>" . $e->getMessage() . "</pre>\n";
80 $contents .= "</div class='openid_results'>";
81 include_once 'openid/wrapper.php';
86 if (!empty($_POST['checkid_immediate'])) {
87 $authRequest->setMode('checkid_immediate');
91 if (!empty($_POST['sreg'])) {
92 $sreg = new OpenID_Extension_SREG11(OpenID_Extension::REQUEST);
93 $sreg->set('required', 'email,firstname,lastname,nickname');
94 $sreg->set('optional', 'gender,dob');
95 $authRequest->addExtension($sreg);
99 if (!empty($_POST['ax'])) {
100 $ax = new OpenID_Extension_AX(OpenID_Extension::REQUEST);
101 $ax->set('type.email', 'http://axschema.org/contact/email');
102 $ax->set('type.firstname', 'http://axschema.org/namePerson/first');
103 $ax->set('type.lastname', 'http://axschema.org/namePerson/last');
104 $ax->set('mode', 'fetch_request');
105 $ax->set('required', 'email,firstname,lastname');
106 $authRequest->addExtension($ax);
110 if (!empty($_POST['ui'])) {
111 $ui = new OpenID_Extension_UI(OpenID_Extension::REQUEST);
112 $ui->set('mode', 'popup');
113 $ui->set('language', 'en-US');
114 $authRequest->addExtension($ui);
118 if (!empty($_POST['oauth'])) {
119 $oauth = new OpenID_Extension_OAuth(OpenID_Extension::REQUEST);
120 $oauth->set('consumer', $_POST['oauth_consumer_key']);
121 $_SESSION['OAuth_consumer_key'] = $_POST['oauth_consumer_key'];
122 $_SESSION['OAuth_consumer_secret'] = $_POST['oauth_consumer_secret'];
124 $oauth->set('scope', $_POST['oauth_scope']);
125 $_SESSION['OAuth_scope'] = $_POST['oauth_scope'];
127 $_SESSION['OAuth_access_token_url'] = $_POST['oauth_access_token_url'];
128 $_SESSION['OAuth_access_token_method'] = $_POST['oauth_access_token_method'];
130 $authRequest->addExtension($oauth);
133 $url = $authRequest->getAuthorizeURL();
135 if (empty($_POST['debug'])) {
136 header("Location: $url");
141 if (isset($_SESSION['identifier'])) {
142 $usid = $_SESSION['identifier'];
143 unset($_SESSION['identifier']);
148 unset($_SESSION['disable_associations']);
150 if (!count($_POST)) {
151 list(, $queryString) = explode('?', $_SERVER['REQUEST_URI']);
153 // I hate php sometimes
154 $queryString = file_get_contents('php://input');
157 $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP);
158 $id = $message->get('openid.claimed_id');
159 $mode = $message->get('openid.mode');
162 $result = $o->verify(new Net_URL2($returnTo . '?' . $queryString),
165 if ($result->success()) {
166 $status = "<tr><td>Status:</td><td><font color='green'>SUCCESS!";
167 $status .= " ({$result->getAssertionMethod()})</font></td></tr>";
169 $status = "<tr><td>Status:</td><td><font color='red'>FAIL!";
170 $status .= " ({$result->getAssertionMethod()})</font></td></tr>";
172 } catch (OpenID_Exception $e) {
173 $status = "<tr><td>Status:</td><td><font color='red'>EXCEPTION!";
174 $status .= " ({$e->getMessage()} : {$e->getCode()})</font></td></tr>";
177 // OAuth hyprid fetching access token
178 if (isset($_SESSION['OAuth_consumer_key'],
179 $_SESSION['OAuth_consumer_secret'],
180 $_SESSION['OAuth_access_token_url'],
181 $_SESSION['OAuth_access_token_method'])) {
184 $oauth = new OpenID_Extension_OAuth(OpenID_Extension::RESPONSE,
188 $consumerKey = $_SESSION['OAuth_consumer_key'];
189 $consumerSecret = $_SESSION['OAuth_consumer_key'];
190 $tokenURL = $_SESSION['OAuth_access_token_url'];
191 $tokenMethod = $_SESSION['OAuth_access_token_method'];
193 $oauthData = $oauth->getAccessToken($consumerKey,
199 } catch (Exception $e) {
203 $contents = "<div class='openid_results'>
206 <tr colspan=2><td><b>Results</b></td></tr>
207 <tr><td>User Supplied Identifier:</td><td>$usid</td></tr>
208 <tr><td>Claimed Identifier:</td><td>$id</td></tr>
209 <tr><td>Mode:</td><td>$mode</td></tr>
211 <tr colspan=2><td><p><br><b>Message Contents</b></td></tr>";
213 foreach ($message->getArrayFormat() as $key => $value) {
214 $contents .= "<tr><td align=left>$key</td><td>$value</td></tr>\n";
217 if (isset($oauthData) && count($oauthData)) {
218 $contents .= "<tr colspan=2>";
219 $contents .= " <td><p><br><b>OAuth Access token/secret</b></td>";
220 $contents .= "</tr>";
222 foreach ($oauthData as $key => $value) {
223 $contents .= "<tr><td align=left>$key</td><td>$value</td></tr>\n";
227 $contents .= "</table>";
228 $contents .= "</div>";
230 $openid = $message->getArrayFormat();
231 if ($GLOBALS['phorkie']['auth']['secure'] > 0 &&
232 $GLOBALS['phorkie']['auth']['userlist']) {
233 if (!in_array($openid['openid.identity'], $GLOBALS['phorkie']['users'])) {
234 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . "/forbidden";
235 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
239 // include_once 'openid/wrapper.php';
241 $email = (isset($openid['openid.ext1.value.email'])) ? $openid['openid.ext1.value.email'] : null;
242 $email = (isset($openid['openid.ext2.value.email']) && !isset($email)) ? $openid['openid.ext2.value.email'] : $email;
243 $email = (isset($openid['openid.sreg.email']) && !isset($email)) ? $openid['openid.sreg.email'] : $email;
244 $email = (isset($openid['openid.ax.value.email']) && !isset($email)) ? $openid['openid.ax.value.email'] : $email;
245 $_SESSION['email'] = (isset($email)) ? $email : $GLOBALS['phorkie']['auth']['anonymousEmail'];
247 $name = (isset($openid['openid.ext1.value.firstname']) && isset($openid['openid.ext1.value.lastname'])) ? $openid['openid.ext1.value.firstname']." ".$openid['openid.ext1.value.lastname'] : null;
248 $name = (isset($openid['openid.sreg.firstname']) && isset($openid['openid.sreg.lastname']) && !isset($name)) ? $openid['openid.sreg.firstname']." ".$openid['openid.sreg.lastname'] : $name;
249 $name = (isset($openid['openid.sreg.nickname']) && !isset($name)) ? $openid['openid.sreg.nickname'] : $name;
250 $_SESSION['name'] = (isset($name)) ? $name : $_SERVER['REMOTE_ADDR'];
252 $_SESSION['identity'] = $openid['openid.identity'];
254 $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SESSION['REQUEST_URI'];
255 header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));