爲什麼要做一個自動的HTML文章而不是簡單的重定向?爲什麼在OpenID 2中使用HTML表單重定向?
這是否使開發人員可以自動生成登錄表單,在OpenID已知時將目錄發佈到遠程服務器?
例如。
- 用戶未登錄並訪問您的登錄頁面。
- 您從cookie中檢測到用戶的openID。
- 生成表單,直接發佈到遠程OpenID服務器。
- 遠程服務器將用戶重定向回網站。
- 網站登錄用戶。
如果是這種情況,我可以看到好處。但是,這假定您在註銷時將用戶的openID保存在cookie中。
我可以找到有關如何最好地實現此規範的信息很少。
查看HTML表單重定向在官方規格:
http://openid.net/specs/openid-authentication-2_0.html#indirect_comm
我發現了這一點,從看PHP OpenID Library(2.1.1版本)。
// 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;
}
}
請參閱http://trac.openidenabled.com/trac/ticket/376。 – crb 2010-02-12 15:08:50