简体   繁体   English

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

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

I have built a lot of internal applications at my company. 我在公司建立了很多内部应用程序。 And my programming is on the the database/app level. 我的编程是在数据库/应用程序级别上。 Most of my applications have been using the same login/authentication class for years. 我的大多数应用程序多年来一直使用相同的登录/身份验证类。 However, said company wants everything going through their SSO authentication application. 但是,该公司希望一切都通过其SSO身份验证应用程序进行。 They have sent me their SSO application URL, the fields names they are passing, my sites actionURL, and my appKey. 他们向我发送了他们的SSO应用程序URL,他们传递的字段名称,网站actionURL和我的appKey。

All of my applications are on the same domain. 我所有的应用程序都在同一个域中。 I understand that I can set cookies to work on entire domain and have that set. 我了解可以将Cookie设置为可在整个域上使用并进行设置。 Right now I am a bit stuck because I wrote some very simple test code. 现在,由于我编写了一些非常简单的测试代码,我有些困惑。 It is taking users to the SSO server and authenticating and sending the back over to my actionURL which is just my root of my domain. 它会将用户带到SSO服务器,并进行身份验证并将其发送回我的actionURL(这是我的域的根目录)。

So I am trying to request a URL that is behind my code, it shows that I need to be authenticated, passes me to the SSO app, and then I get passed back to my actionURL. 因此,我尝试请求代码背后的URL,它表明我需要进行身份验证,将我传递给SSO应用程序,然后再传递回我的actionURL。 What do I need on my actionURL to allow me to navigate through my apps. 我需要在actionURL上执行什么操作才能浏览应用程序。

Current code: 当前代码:

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);
}

Additional info - All of my applications are mysql and php based. 附加信息-我所有的应用程序均基于mysql和php。 So I need to bring my mysql piece into it. 因此,我需要将mysql片段放入其中。 I need something that says yes you are authorized, your username was passed over, and now we will look you up in the mysql database and use your corresponding row for rights/access. 我需要说是的,您已被授权,您的用户名已通过,现在我们将在mysql数据库中查找您并使用您对应的行进行权限/访问。 Does that make sense? 那有意义吗? Trying to write that part right now. 立即尝试编写该部分。

In your case, there has to be a mapping between the users in your MySQL db and the SSO server. 在您的情况下,您的MySQL数据库中的用户和SSO服务器之间必须存在映射。 A simple one would be an email address. 一个简单的地址就是电子邮件地址。 A better one would be a GUID - globally unique ID. 更好的是GUID-全局唯一ID。 Whetever it is, the SSO server should pass a unique ID identifying the user when it calls your actionURL ( in SSO terms... your callback url). 无论如何,SSO服务器在调用actionURL(以SSO术语...您的回调URL)时应传递一个唯一的ID来标识用户。

Once you get the unique ID, retrieve the user from your MySQL DB using that ID. 一旦获得唯一ID,就可以使用该ID从MySQL数据库中检索用户。 If he exists, log him in. 如果他存在,请登录。

Normally, the SSO server will create a cookie which your applications can see. 通常,SSO服务器将创建一个cookie,您的应用程序可以看到该cookie。 This should indicate if your user is logged in or not ( so you don't have to keep going back to the Server to authenticate a user). 这应该表明您的用户是否登录(因此您不必继续返回到服务器来验证用户身份)。

HTH 高温超导

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

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