diff options
author | Cash Costello <cash.costello@gmail.com> | 2011-12-11 06:38:23 -0500 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2011-12-11 06:38:23 -0500 |
commit | d9bf22a0e29c2a70049443a0ae8521a2c0492c8b (patch) | |
tree | c7599a9169d5def7df56c480ad6d67f312443d6f /models/openid-php-openid-782224d/examples/consumer/try_auth.php | |
download | elgg-d9bf22a0e29c2a70049443a0ae8521a2c0492c8b.tar.gz elgg-d9bf22a0e29c2a70049443a0ae8521a2c0492c8b.tar.bz2 |
initial commit for git repository
Diffstat (limited to 'models/openid-php-openid-782224d/examples/consumer/try_auth.php')
-rw-r--r-- | models/openid-php-openid-782224d/examples/consumer/try_auth.php | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/models/openid-php-openid-782224d/examples/consumer/try_auth.php b/models/openid-php-openid-782224d/examples/consumer/try_auth.php new file mode 100644 index 000000000..7efec7657 --- /dev/null +++ b/models/openid-php-openid-782224d/examples/consumer/try_auth.php @@ -0,0 +1,83 @@ +<?php + +require_once "common.php"; +session_start(); + +function getOpenIDURL() { + // Render a default page if we got a submission without an openid + // value. + if (empty($_GET['openid_identifier'])) { + $error = "Expected an OpenID URL."; + include 'index.php'; + exit(0); + } + + return $_GET['openid_identifier']; +} + +function run() { + $openid = getOpenIDURL(); + $consumer = getConsumer(); + + // Begin the OpenID authentication process. + $auth_request = $consumer->begin($openid); + + // No auth request means we can't begin OpenID. + if (!$auth_request) { + displayError("Authentication error; not a valid OpenID."); + } + + $sreg_request = Auth_OpenID_SRegRequest::build( + // Required + array('nickname'), + // Optional + array('fullname', 'email')); + + if ($sreg_request) { + $auth_request->addExtension($sreg_request); + } + + $policy_uris = $_GET['policies']; + + $pape_request = new Auth_OpenID_PAPE_Request($policy_uris); + if ($pape_request) { + $auth_request->addExtension($pape_request); + } + + // Redirect the user to the OpenID server for authentication. + // Store the token for this authentication so we can verify the + // response. + + // For OpenID 1, send a redirect. For OpenID 2, use a Javascript + // form to send a POST request to the server. + if ($auth_request->shouldSendRedirect()) { + $redirect_url = $auth_request->redirectURL(getTrustRoot(), + getReturnTo()); + + // If the redirect URL can't be built, display an error + // message. + if (Auth_OpenID::isFailure($redirect_url)) { + displayError("Could not redirect to server: " . $redirect_url->message); + } else { + // Send redirect. + header("Location: ".$redirect_url); + } + } else { + // Generate form markup and render it. + $form_id = 'openid_message'; + $form_html = $auth_request->htmlMarkup(getTrustRoot(), getReturnTo(), + false, array('id' => $form_id)); + + // Display an error if the form markup couldn't be generated; + // otherwise, render the HTML. + if (Auth_OpenID::isFailure($form_html)) { + displayError("Could not redirect to server: " . $form_html->message); + } else { + print $form_html; + } + } +} + +run(); + +?>
\ No newline at end of file |