summaryrefslogtreecommitdiffstats
path: root/Auth
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2007-10-01 20:06:05 +0000
committertailor <cygnus@janrain.com>2007-10-01 20:06:05 +0000
commitde5e156cdbcfb53231b81db571e19ad0f920d51f (patch)
treeab8fb56209bbdf662bdf63da197340a1d06bdb6b /Auth
parente198e7b3f3e2d0ec2c503a27f262fee54becf455 (diff)
downloadphp-openid-de5e156cdbcfb53231b81db571e19ad0f920d51f.zip
php-openid-de5e156cdbcfb53231b81db571e19ad0f920d51f.tar.gz
php-openid-de5e156cdbcfb53231b81db571e19ad0f920d51f.tar.bz2
[project @ Auth_OpenID_GenericConsumer::_extractSupporedAssociationType: factored out from _negotiateAssociation]
Diffstat (limited to 'Auth')
-rw-r--r--Auth/OpenID/Consumer.php83
1 files changed, 47 insertions, 36 deletions
diff --git a/Auth/OpenID/Consumer.php b/Auth/OpenID/Consumer.php
index 7aa897b..f8f1089 100644
--- a/Auth/OpenID/Consumer.php
+++ b/Auth/OpenID/Consumer.php
@@ -1379,6 +1379,45 @@ class Auth_OpenID_GenericConsumer {
return $assoc;
}
+ /*
+ * Handle ServerErrors resulting from association requests.
+ *
+ * @return $result If server replied with an C{unsupported-type}
+ * error, return a tuple of supported C{association_type},
+ * C{session_type}. Otherwise logs the error and returns null.
+ */
+ function _extractSupportedAssociationType(&$server_error, &$endpoint,
+ $assoc_type)
+ {
+ // Any error message whose code is not 'unsupported-type'
+ // should be considered a total failure.
+ if (($server_error->error_code != 'unsupported-type') ||
+ ($server_error->message->isOpenID1())) {
+ return null;
+ }
+
+ // The server didn't like the association/session type that we
+ // sent, and it sent us back a message that might tell us how
+ // to handle it.
+
+ // Extract the session_type and assoc_type from the error
+ // message
+ $assoc_type = $server_error->message->getArg(Auth_OpenID_OPENID_NS,
+ 'assoc_type');
+
+ $session_type = $server_error->message->getArg(Auth_OpenID_OPENID_NS,
+ 'session_type');
+
+ if (($assoc_type === null) || ($session_type === null)) {
+ return null;
+ } else if (!$this->negotiator->isAllowed($assoc_type,
+ $session_type)) {
+ return null;
+ } else {
+ return array($assoc_type, $session_type);
+ }
+ }
+
/**
* @access private
*/
@@ -1397,42 +1436,12 @@ class Auth_OpenID_GenericConsumer {
if (is_a($assoc, 'Auth_OpenID_ServerErrorContainer')) {
$why = $assoc;
- // Any error message whose code is not 'unsupported-type'
- // should be considered a total failure.
- if (($why->error_code != 'unsupported-type') ||
- ($why->message->isOpenID1())) {
- // oidutil.log(
- // 'Server error when requesting an association from %r: %s'
- // % (endpoint.server_url, why.error_text))
- return null;
- }
+ $supportedTypes = $this->_extractSupportedAssociationType(
+ $why, $endpoint, $assoc_type);
- // The server didn't like the association/session type
- // that we sent, and it sent us back a message that
- // might tell us how to handle it.
- // oidutil.log(
- // 'Unsupported association type %s: %s' % (assoc_type,
- // why.error_text,))
+ if ($supportedTypes !== null) {
+ list($assoc_type, $session_type) = $supportedTypes;
- // Extract the session_type and assoc_type from the
- // error message
- $assoc_type = $why->message->getArg(Auth_OpenID_OPENID_NS,
- 'assoc_type');
-
- $session_type = $why->message->getArg(Auth_OpenID_OPENID_NS,
- 'session_type');
-
- if (($assoc_type === null) || ($session_type === null)) {
- // oidutil.log('Server responded with unsupported association '
- // 'session but did not supply a fallback.')
- return null;
- } else if (!$this->negotiator->isAllowed($assoc_type,
- $session_type)) {
- // fmt = ('Server sent unsupported session/association type: '
- // 'session_type=%s, assoc_type=%s')
- // oidutil.log(fmt % (session_type, assoc_type))
- return null;
- } else {
// Attempt to create an association from the assoc_type
// and session_type that the server told us it
// supported.
@@ -1450,10 +1459,12 @@ class Auth_OpenID_GenericConsumer {
} else {
return $assoc;
}
+ } else {
+ return null;
}
+ } else {
+ return $assoc;
}
-
- return $assoc;
}
/**