Source for file Assertion.php
Documentation is available at Assertion.php
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
require_once 'OpenID.php';
require_once 'OpenID/Discover.php';
require_once 'OpenID/Assertion/Exception.php';
require_once 'OpenID/Assertion/Exception/NoClaimedID.php';
require_once 'OpenID/Message.php';
require_once 'OpenID/Nonce.php';
require_once 'Validate.php';
require_once 'Net/URL2.php';
* Class for verifying assertions. Does basic validation (nonce, return_to, etc),
* as well as signature verification and check_authentication.
* @author Bill Shupp <hostmaster@shupp.org>
* @copyright 2009 Bill Shupp
* @license http://www.opensource.org/licenses/bsd-license.php FreeBSD
* @link http://pearopenid.googlecode.com
* Response message passed to the constructor
* The URL of the current request (to compare with openid.return_to)
* The clock skew limit for checking nonces.
* Sets the request message, url, and clock skew. Then does some basic
* validation (return_to, nonce, discover).
* @param OpenID_Message $message Message from the request
* @param Net_URL2 $requestedURL The requested URL
* @param int $clockSkew Nonce clock skew in seconds
// Don't check return_to for a negative checkid_immadiate 1.1 response
if ($message->get('openid.ns') !==
null
||
$message->get('openid.user_setup_url') ===
null) {
if ($message->get('openid.ns') !==
null) {
* Verifies the signature of this message association.
* @param OpenID_Association $assoc Association to use for checking the signature
* @return bool result of OpenID_Association::checkMessageSignature()
* @see OpenID_Association::checkMessageSignature()
return $assoc->checkMessageSignature($this->message);
* Performs a check_authentication request.
* @param array $options Options to pass to HTTP_Request
* @return OpenID_Message Reponse to the check_authentication request
$opURL =
$this->message->get('openid.op_endpoint');
* Validates the openid.return_to parameter in the response.
* @throws OpenID_Assertion_Exception on failure
$returnTo =
$this->message->get('openid.return_to');
'openid.return_to: ' .
var_export($returnTo, true));
// Validate openid.return_to
if (!Validate::uri($returnTo)) {
'openid.return_to parameter is invalid or missing'
$obj1 =
new Net_URL2($returnTo);
$queryString1 =
$obj1->getQueryVariables();
$queryString2 =
$obj2->getQueryVariables();
$obj1->setQueryVariables(array());
$obj2->setQueryVariables(array());
if ($obj1->getURL() !=
$obj2->getURL()) {
'openid.return_to does not match the requested URL'
if (!count($queryString1) &&
!count($queryString2)) {
foreach ($queryString1 as $param =>
$value) {
if (!isset
($queryString2[$param])
||
$queryString2[$param] !=
$value) {
'openid.return_to parameters do not match requested url'
* Validates and performs discovery on the openid.claimed_id paramter.
* @throws OpenID_Assertion_Exception on failure
$claimedID =
$this->message->get('openid.claimed_id');
if ($claimedID ===
null) {
'No claimed_id in message'
if ($claimedID ===
OpenID::SERVICE_2_0_SERVER) {
'Claimed identifier cannot be an OP identifier'
$url =
new Net_URL2($claimedID);
// Remove the fragment, per the spec
$url->setFragment(false);
'Unable to discover claimed_id'
$opURL =
array_shift($discover->services[0]->getURIs());
if ($opURL !==
$this->message->get('openid.op_endpoint')) {
'This OP is not authorized to issue assertions for this claimed id'
* Validates the openid.response_nonce parameter.
* @throws OpenID_Assertion_Exception on invalid or existing nonce
$opURL =
$this->message->get('openid.op_endpoint');
$responseNonce =
$this->message->get('openid.response_nonce');
if (!$nonce->verifyResponseNonce($responseNonce)) {
'Invalid or already existing response_nonce'
* Validates the nonce embedded in the openid.return_to paramater and deletes
* it from storage.. (For use with OpenID 1.1 only)
* @throws OpenID_Assertion_Exception on invalid or non-existing nonce
$returnTo =
$this->message->get('openid.return_to');
if ($returnTo ===
null) {
// Must be a checkid_immediate negative assertion.
$rtURL2 =
new Net_URL2($this->message->get('openid.user_setup_url'));
$rtqs =
$rtURL2->getQueryVariables();
$returnTo =
$rtqs['openid.return_to'];
$identity =
$rtqs['openid.identity'];
$netURL =
new Net_URL2($returnTo);
$qs =
$netURL->getQueryVariables();
'Missing OpenID 1.1 return_to nonce'
$identity =
$this->message->get('openid.identity');
$endPoint =
$discover->services[0];
$fromStore =
self::getStore()->getNonce(urldecode($nonce), $opURL);
$logMessage =
"returnTo: $returnTo\n";
$logMessage .=
'OP URIs: ' .
print_r($endPoint->getURIs(), true) .
"\n";
$logMessage .=
'Nonce in storage?: ' .
var_export($fromStore, true) .
"\n";
'Invalid OpenID 1.1 return_to nonce in response'
self::getStore()->deleteNonce($nonce, $opURL);
* Gets an instance of OpenID_Discover. Abstracted for testing.
* @param string $identifier OpenID Identifier
* @return OpenID_Discover|false
Documentation generated on Tue, 15 Dec 2009 19:00:50 -0800 by phpDocumentor 1.4.3