繁体   English   中英

PHP-说明我的SSO身份验证所需的步骤

[英]PHP - Explain steps needed for my SSO authentication

我在公司建立了很多内部应用程序。 我的编程是在数据库/应用程序级别上。 我的大多数应用程序多年来一直使用相同的登录/身份验证类。 但是,该公司希望一切都通过其SSO身份验证应用程序进行。 他们向我发送了他们的SSO应用程序URL,他们传递的字段名称,网站actionURL和我的appKey。

我所有的应用程序都在同一个域中。 我了解可以将Cookie设置为可在整个域上使用并进行设置。 现在,由于我编写了一些非常简单的测试代码,我有些困惑。 它会将用户带到SSO服务器,并进行身份验证并将其发送回我的actionURL(这是我的域的根目录)。

因此,我尝试请求代码背后的URL,它表明我需要进行身份验证,将我传递给SSO应用程序,然后再传递回我的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数据库中查找您并使用您对应的行进行权限/访问。 那有意义吗? 立即尝试编写该部分。

在您的情况下,您的MySQL数据库中的用户和SSO服务器之间必须存在映射。 一个简单的地址就是电子邮件地址。 更好的是GUID-全局唯一ID。 无论如何,SSO服务器在调用actionURL(以SSO术语...您的回调URL)时应传递一个唯一的ID来标识用户。

一旦获得唯一ID,就可以使用该ID从MySQL数据库中检索用户。 如果他存在,请登录。

通常,SSO服务器将创建一个cookie,您的应用程序可以看到该cookie。 这应该表明您的用户是否登录(因此您不必继续返回到服务器来验证用户身份)。

高温超导

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM