Skip to content

Commit 418aeea

Browse files
committed
Add error handling to constructing openid message
Signed-off-by: Michal Čihař <michal@cihar.com>
1 parent 94cf386 commit 418aeea

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

Diff for: examples/openid.php

+17-11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ function Show_page($contents)
6363
<?php
6464
}
6565

66+
function Die_error($e)
67+
{
68+
$contents = "<div class='relyingparty_results'>\n";
69+
$contents .= "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>\n";
70+
$contents .= "</div class='relyingparty_results'>";
71+
Show_page($contents);
72+
exit;
73+
}
74+
75+
6676
/* Need to have cookie visible from parent directory */
6777
session_set_cookie_params(0, '/', '', false);
6878
/* Create signon session */
@@ -110,23 +120,15 @@ function Show_page($contents)
110120
try {
111121
$o = new OpenID_RelyingParty($returnTo, $realm, $identifier);
112122
} catch (Exception $e) {
113-
$contents = "<div class='relyingparty_results'>\n";
114-
$contents .= "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>\n";
115-
$contents .= "</div class='relyingparty_results'>";
116-
Show_page($contents);
117-
exit;
123+
Die_error($e);
118124
}
119125

120126
/* Redirect to OpenID provider */
121127
if (isset($_POST['start'])) {
122128
try {
123129
$authRequest = $o->prepare();
124130
} catch (Exception $e) {
125-
$contents = "<div class='relyingparty_results'>\n";
126-
$contents .= "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>\n";
127-
$contents .= "</div class='relyingparty_results'>";
128-
Show_page($contents);
129-
exit;
131+
Die_error($e);
130132
}
131133

132134
$url = $authRequest->getAuthorizeURL();
@@ -143,7 +145,11 @@ function Show_page($contents)
143145
}
144146

145147
/* Check reply */
146-
$message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP);
148+
try {
149+
$message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP);
150+
} catch (Exception $e) {
151+
Die_error($e);
152+
}
147153

148154
$id = $message->get('openid.claimed_id');
149155

0 commit comments

Comments
 (0)