【发布时间】:2015-03-11 00:39:22
【问题描述】:
我正在尝试通过使用 OAuth2 进行身份验证的家族历史 Web 服务进行身份验证。身份验证的基本工作流程是,我针对请求身份验证会话的 Web 服务提交获取请求。它在响应 HTML 代码的正文中返回,其中包含一些用于用户名和密码的登录组件。然后,我的 PHP 应用程序将 html 代码回显到浏览器。然后,最终用户可以输入他或她的用户名和密码,然后提交到 Web 服务。这是行为变得不清楚的地方。理论上,Web 服务应该重定向到预定义的重定向 URI,其中包含一些参数。然而,在实践中,提交密码重定向到预先注册的重定向 URI,但 URL 中不包含任何参数。我的项目主要是用 PHP 编写的。这是对身份验证会话发出初始请求的代码片段。
function logOn($mainURL, $credentials)
{
// create a new HTTP_Request object to be used in the login process
$request = new HTTP_Request();
// set the URL of the HTTP_Request object to the family search identity/login endpoint
$request->setUrl("https://web-service/authentication/path?response_type=code&client_id=".$credentials['key']."&redirect_uri=https://www.myredirectPage.edu/");
$request->_useBrackets = false;
$request->addHeader("User-Agent", $credentials['agent']);
$request->addHeader("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
$request->sendRequest();
//HTML_HEADER;
//the response will come in the form of an html file
$responseHtml = $request->getResponseBody();
//Dynamically load html from request body onto the browser to allow for authentication
echo $responseHtml;
return $credentials;
}
最终用户将使用加载的 html 组件输入他们的登录凭据并点击提交。 Web 服务然后重定向到我的重定向身份验证页面。代码如下。
<?php
// process client request (Via url)
//gather code parameters from the redirect url.
if (isset($_GET['code']))
{
echo $_GET['code'];
}
else
{
echo "code not returned";
}
if (isset($_GET['error']))
{
echo $_GET['error'];
}
else
{
echo "error not returned";
}
?>
在此先感谢您的帮助。
【问题讨论】: