我已经在我的公司构建了很多内部应用程序。我的编程是数据库/应用程序级别的。我的大多数应用程序多年来一直使用相同的登录/身份验证类。然而,说公司希望所有的东西都通过他们的SSO身份验证应用程序。他们已经向我发送了他们的单点登录应用程序URL、他们传递的字段名称、我的站点actionURL和我的appKey。
我的所有应用程序都在同一个域上。我知道我可以设置cookie在整个域上工作,并有该设置。现在我有点卡住了,因为我写了一些非常简单的测试代码。
因此,我尝试请求代码后面的URL,它显示我需要进行身份验证,将我传递给单点登录应用程序,然后我被传递回我的actionURL。我的actionURL上需要什么才能允许我浏览我的应用程序。
当前代码:
session_start();
if ($_POST && isset($_POST['digest']))
{
$digest = $_POST["digest"];
// set the session variables ...
$_SESSION['username'] = $_POST["firstname"]." ".$_POST["lastname"];
$_SESSION['firstname'] = $_POST["firstname"];
$_SESSION['lastname'] = $_POST["lastname"];
$_SESSION['email'] = $_POST["email"];
$_SESSION['uid'] = $_POST["uid"];
// Needed for key
$uid = $_POST["uid"];
$time = $_POST["time"];
// Read the property file with the key and URL so this won't go into the main code ...
// this sets $appKey and $safeurl
require_once("safe_login_properties.php");
$mykey = "".$uid.$time.$appKey;
$mydigest = md5($mykey);
if ($debugthis) // enable this for some debugging
{
$fp = fopen("DebugInfo.txt", "a");
fprintf($fp, "%s\n", date("H:i:s"));
foreach($_POST as $p => $v)
{
fprintf($fp, "POST: %s: %s\n", $p, $v);
}
foreach($_SESSION as $p => $v)
{
fprintf($fp, "SESSION: %s: %s\n", $p, $v);
}
fprintf($fp, "mykey: %s (uid: %s, time %s, key %s)\n", $mykey, $uid, $time, $appKey);
fprintf($fp, "posted digest: %s\n", $digest);
fprintf($fp, "mydigest: %s\n", $mydigest);
if ($digest == $mydigest)
fprintf($fp, "Digest match\n");
else
fprintf($fp, "***** digest does not match\n");
fclose($fp);
}
if ($digest != $mydigest)
{
die("Invalid login - expected digest does not match");
}
}
if (!isset($_SESSION['username']) || empty($_SESSION['username']))
{
// Read the property file with the key and URL so this won't go into the main code ...
// this sets $appKey and $safeurl
require_once("safe_login.php");
header("Location: ".$safeurl);
}附加信息-我所有的应用程序都是基于mysql和php的。所以我需要把我的mysql代码放进去。我需要一些东西,说你是被授权的,你的用户名被传递了,现在我们将在mysql数据库中查找你,并使用你相应的行进行权限/访问。这有意义吗?现在就试着写那部分。
发布于 2013-04-23 03:28:52
在您的示例中,MySQL数据库中的用户和单点登录服务器之间必须有一个映射。一个简单的方法是一个电子邮件地址。更好的方法是使用GUID -全局唯一ID。您的回调url)。
获得唯一ID后,使用该ID从MySQL数据库中检索该用户。如果该用户存在,请将其登录。
通常,SSO服务器将创建一个您的应用程序可以看到的cookie。这应该表明您的用户是否已登录(这样您就不必一直返回服务器来验证用户)。
HTH
https://stackoverflow.com/questions/16096742
复制相似问题