summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Auth/OpenID.php9
-rw-r--r--Auth/OpenID/Consumer.php18
-rw-r--r--Auth/OpenID/Server.php19
-rw-r--r--Tests/Auth/OpenID/Consumer.php23
4 files changed, 67 insertions, 2 deletions
diff --git a/Auth/OpenID.php b/Auth/OpenID.php
index 41e850b..0c071b9 100644
--- a/Auth/OpenID.php
+++ b/Auth/OpenID.php
@@ -557,5 +557,14 @@ class Auth_OpenID {
$message = call_user_func_array('sprintf', $args);
error_log($message);
}
+
+ function autoSubmitHTML($form)
+ {
+ return("<html>".
+ "<body onload='document.forms[0].submit();'>".
+ $form .
+ "</body>".
+ "</html>");
+ }
}
?>
diff --git a/Auth/OpenID/Consumer.php b/Auth/OpenID/Consumer.php
index d5fd53f..3619e5a 100644
--- a/Auth/OpenID/Consumer.php
+++ b/Auth/OpenID/Consumer.php
@@ -1935,6 +1935,24 @@ class Auth_OpenID_AuthRequest {
$form_tag_attrs);
}
+ /**
+ * Get a complete html document that will autosubmit the request
+ * to the IDP.
+ *
+ * Wraps formMarkup. See the documentation for that function.
+ */
+ function htmlMarkup($realm, $return_to=null, $immediate=false,
+ $form_tag_attrs=null)
+ {
+ $form = $this->formMarkup($realm, $return_to, $immediate,
+ $form_tag_attrs);
+
+ if (Auth_OpenID::isFailure($form)) {
+ return $form;
+ }
+ return Auth_OpenID::autoSubmitHTML($form);
+ }
+
function shouldSendRedirect()
{
return $this->endpoint->compatibilityMode();
diff --git a/Auth/OpenID/Server.php b/Auth/OpenID/Server.php
index 0d91769..70283a3 100644
--- a/Auth/OpenID/Server.php
+++ b/Auth/OpenID/Server.php
@@ -205,10 +205,16 @@ class Auth_OpenID_ServerError {
'error' => $this->toString()));
}
- function toFormMarkup()
+ function toFormMarkup($form_tag_attrs=null)
{
$msg = $this->toMessage();
- return $msg->toFormMarkup($this->getReturnTo());
+ return $msg->toFormMarkup($this->getReturnTo(), $form_tag_attrs);
+ }
+
+ function toHTML($form_tag_attrs=null)
+ {
+ return Auth_OpenID::autoSubmitHTML(
+ $this->toFormMarkup($form_tag_attrs));
}
function toMessage()
@@ -1193,6 +1199,15 @@ class Auth_OpenID_ServerResponse {
}
/*
+ * Returns an HTML document containing the form markup for this
+ * response that autosubmits with javascript.
+ */
+ function toHTML()
+ {
+ return Auth_OpenID::autoSubmitHTML($this->toFormMarkup());
+ }
+
+ /*
* Returns True if this response's encoding is ENCODE_HTML_FORM.
* Convenience method for server authors.
*
diff --git a/Tests/Auth/OpenID/Consumer.php b/Tests/Auth/OpenID/Consumer.php
index 2a02926..148d6f3 100644
--- a/Tests/Auth/OpenID/Consumer.php
+++ b/Tests/Auth/OpenID/Consumer.php
@@ -1632,6 +1632,28 @@ class Tests_Auth_OpenID_Consumer_TestFetchAssoc extends PHPUnit_TestCase {
}
}
+class Tests_Auth_OpenID_AuthRequestHTMLMarkup extends PHPUnit_TestCase {
+ function setUp()
+ {
+ $this->endpoint = new Auth_OpenID_ServiceEndpoint();
+ $this->endpoint->claimed_id = 'identity_url';
+
+ $this->request = new Auth_OpenID_AuthRequest($this->endpoint, null);
+ }
+
+ function test_htmlMarkup()
+ {
+ $html = $this->request->htmlMarkup('http://realm.com/',
+ 'http://realm.com/return_to');
+ $this->assertTrue(substr($html,"<html>") !== false);
+ $this->assertTrue(substr($html,"</html>") !== false);
+ $this->assertTrue(substr($html,"<body onload") !== false);
+ $this->assertTrue(substr($html,"</body>") !== false);
+ $this->assertTrue(substr($html,"<form") !== false);
+ $this->assertTrue(substr($html,"</form>") !== false);
+ }
+}
+
class Tests_Auth_OpenID_SuccessResponse extends PHPUnit_TestCase {
function setUp()
{
@@ -2448,6 +2470,7 @@ class Tests_Auth_OpenID_KVPost extends PHPUnit_TestCase {
global $Tests_Auth_OpenID_Consumer_other;
$Tests_Auth_OpenID_Consumer_other = array(
// new Tests_Auth_OpenID_Consumer_TestSetupNeeded(),
+ new Tests_Auth_OpenID_AuthRequestHTMLMarkup(),
new Tests_Auth_OpenID_Consumer_TestCheckAuth(),
new Tests_Auth_OpenID_Consumer_TestCheckAuthTriggered(),
new Tests_Auth_OpenID_Consumer_TestFetchAssoc(),