Skip to content

Commit

Permalink
Add error handling to constructing openid message
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 17, 2016
1 parent 52e7898 commit d005ba6
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions examples/openid.php
Expand Up @@ -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 */
Expand Down Expand Up @@ -110,23 +120,15 @@ function Show_page($contents)
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 */
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();
Expand All @@ -143,7 +145,11 @@ function Show_page($contents)
}

/* 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');

Expand Down

0 comments on commit d005ba6

Please sign in to comment.