diff options
author | Michal Čihař <michal@cihar.com> | 2016-06-17 15:33:33 +0300 |
---|---|---|
committer | Michal Čihař <michal@cihar.com> | 2016-06-17 15:34:50 +0300 |
commit | 418aeea3d83b0b6021bac311d849570acfc6e48c (patch) | |
tree | fef96bcae16c568e34365d1e18e2dfad04094231 /examples | |
parent | 94cf3864254ffaf3a69e97d8fc454888368b94ab (diff) |
Add error handling to constructing openid message
Signed-off-by: Michal Čihař <michal@cihar.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/openid.php | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/examples/openid.php b/examples/openid.php index a15189b37a..8ef34e9ee3 100644 --- a/examples/openid.php +++ b/examples/openid.php @@ -63,6 +63,16 @@ function Show_page($contents) <?php } +function Die_error($e) +{ + $contents = "<div class='relyingparty_results'>\n"; + $contents .= "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>\n"; + $contents .= "</div class='relyingparty_results'>"; + Show_page($contents); + exit; +} + + /* Need to have cookie visible from parent directory */ session_set_cookie_params(0, '/', '', false); /* Create signon session */ @@ -110,11 +120,7 @@ if (isset($_POST['identifier']) && is_string($_POST['identifier'])) { try { $o = new OpenID_RelyingParty($returnTo, $realm, $identifier); } catch (Exception $e) { - $contents = "<div class='relyingparty_results'>\n"; - $contents .= "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>\n"; - $contents .= "</div class='relyingparty_results'>"; - Show_page($contents); - exit; + Die_error($e); } /* Redirect to OpenID provider */ @@ -122,11 +128,7 @@ if (isset($_POST['start'])) { try { $authRequest = $o->prepare(); } catch (Exception $e) { - $contents = "<div class='relyingparty_results'>\n"; - $contents .= "<pre>" . htmlspecialchars($e->getMessage()) . "</pre>\n"; - $contents .= "</div class='relyingparty_results'>"; - Show_page($contents); - exit; + Die_error($e); } $url = $authRequest->getAuthorizeURL(); @@ -143,7 +145,11 @@ if (isset($_POST['start'])) { } /* Check reply */ - $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP); + try { + $message = new OpenID_Message($queryString, OpenID_Message::FORMAT_HTTP); + } catch (Exception $e) { + Die_error($e); + } $id = $message->get('openid.claimed_id'); |