PHP OpenSSO 身份验证

发布于 2024-09-14 02:19:14 字数 1532 浏览 4 评论 0原文

我们目前正在实施新的 OpenSSO 服务器。该服务器与 Web 服务器位于不同的服务器上,并且我在 PHP Web 服务器上进行身份验证时遇到问题。

使用 openSSO 令牌设置的 cookie 称为 iPlanetDirectoryPro。这是从 authServer.company.com 设置的。我需要从 webserver.company.com 读取此内容,然后将 HTTPRequest 发送到 authserver.company.com 以检索该 OpenSSO 令牌的属性。

目前我的代码看起来像这样,但它不起作用,我怀疑是由于没有正确读取 cookie。

$url = 'http://authServer.company.com:8080/opensso/identity/attributes';
$r = new HttpRequest();
$r->setURL($url);
$r->setMethod(HTTP_METH_POST);
$valarray = array(
    'Host' => 'authServer.company.com',
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Cookie' => "iPlanetDirectoryPro=$_COOKIE[iPlanetDirectoryPro]"
    );
$r->addHeaders($valarray);
var_dump($r);
var_dump($valarray);
#
# request
#
print "<br/>";
print "<b>what i'm saying to the server</b>";
print "<pre>";
#print "iPlanetDirectoryPro cookie: $_COOKIE[iPlanetDirectoryPro]";
print $r->getRawRequestMessage();
print "</pre>";

print "iPlanetDirectoryPro cookie: $_COOKIE[iPlanetDirectoryPro]";
$r->send();

#
# response
#
print "<b>what the server is telling me</b>";
print "<pre>";
$response_body = $r->getResponseBody();
print $response_body;
print "</pre>";

对此有什么想法吗?我是否以错误的方式处理这件事?

更新 - 所以我发现的底线是服务器根本无法读取 cookie,因为它来自另一台服务器。作为一项工作,我实现了一个 REST API,允许用户从网络服务器提交登录页面。它发送到 AuthServer,后者返回响应。响应通常应该是一个令牌,除非它无效。如果它是令牌,则会创建一个包含令牌的新 cookie,以便应用程序可以使用该令牌与 authserver 进行通信,但 cookie 驻留在 webservers 域下

We are currently implementing a new OpenSSO Server. The server is on a different server from the web server and I am having trouble getting authentication to occur on our PHP Web server.

The cookie set with the openSSO Token is called iPlanetDirectoryPro. This is set from authServer.company.com . I need to read this from webserver.company.com and then send an HTTPRequest to the authserver.company.com to retrieve the attributes for that OpenSSO Token.

Currently my code looks like this but it isn't working, I suspect due to not correctly reading the cookie.

$url = 'http://authServer.company.com:8080/opensso/identity/attributes';
$r = new HttpRequest();
$r->setURL($url);
$r->setMethod(HTTP_METH_POST);
$valarray = array(
    'Host' => 'authServer.company.com',
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Cookie' => "iPlanetDirectoryPro=$_COOKIE[iPlanetDirectoryPro]"
    );
$r->addHeaders($valarray);
var_dump($r);
var_dump($valarray);
#
# request
#
print "<br/>";
print "<b>what i'm saying to the server</b>";
print "<pre>";
#print "iPlanetDirectoryPro cookie: $_COOKIE[iPlanetDirectoryPro]";
print $r->getRawRequestMessage();
print "</pre>";

print "iPlanetDirectoryPro cookie: $_COOKIE[iPlanetDirectoryPro]";
$r->send();

#
# response
#
print "<b>what the server is telling me</b>";
print "<pre>";
$response_body = $r->getResponseBody();
print $response_body;
print "</pre>";

Any ideas about this? Am I going about this in the wrong way?

Update - So the bottom line I found was the server simply couldn't read the cookie as it was coming from another server. As a work aronud I implemented a REST API that allows the user to submit a login page from the webserver. Its send to the AuthServer which gives back a response. The response should typically be a token unless its invalid. If its a token, a new cookie is created with the token in it so that applications can then use that token to communicate with the authserver, but the cookie resides under the webservers domain

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尴尬癌患者 2024-09-21 02:19:14

显然,401 令牌为空表示您没有随请求发送令牌(或者 OpenSSO 无法从请求中提取令牌)。如果我假设您成功从客户端请求中获取 cookie,那么我建议您尝试将 cookie 值作为参数而不是标头传递。

参数为 subjectid=token 值。

我建议使用curl进行测试以获得正确的请求形式 - 然后修改您的代码以匹配成功的curl请求

Obviously the 401 Token is null indicates that you are not sending the token with the request (or that OpenSSO cannot extract it from the request). If I assume that you are successfully getting the cookie from the client request then I suggest you try passing the cookie value as a param rather than a header to start with.

the param would be subjectid=token value.

I'd recommend testing with curl to get the form of the request right - then modify your code to match the successful curl request

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文