/**
* @throws InvalidArgumentException if an invalid OpenID was provided
*/
public function authenticate($url, $return, $realm, $required = array(), $optional = array())
{
if (empty($realm)) {
$realm = 'http' . (env('HTTPS') ? 's' : '') . '://' . env('SERVER_NAME');
}
if (trim($url) != '') {
$consumer = $this->_consumer();
$authRequest = $consumer->begin($url);
}
if (!isset($authRequest) || !$authRequest) {
throw new InvalidArgumentException('Invalid OpenID');
}
$sregRequest = Auth_OpenID_SRegRequest::build($required, $optional);
if ($sregRequest) {
$authRequest->addExtension($sregRequest);
}
if (!$authRequest->shouldSendRedirect()) {
$formId = 'openid_message';
$formHtml = $authRequest->formMarkup($realm, $return, false, array('id' => $formId));
if (Auth_OpenID::isFailure($formHtml)) {
throw new Exception('Could not redirect to server: ' . $formHtml->message);
}
echo '<html><head><title>OpenID transaction in progress</title></head>' . "<body onload='document.getElementById(\"{$formId}\").submit()'>" . $formHtml . '</body></html>';
exit;
}
$redirectUrl = $authRequest->redirectUrl($realm, $return);
if (Auth_OpenID::isFailure($redirectUrl)) {
throw new Exception('Could not redirect to server: ' . $redirectUrl->message);
}
$this->_controller->redirect($redirectUrl, null, true);
}