Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当cookie存在时,Symfony在不登录的情况下通过UserProviderInterface进行身份验证_Symfony - Fatal编程技术网

当cookie存在时,Symfony在不登录的情况下通过UserProviderInterface进行身份验证

当cookie存在时,Symfony在不登录的情况下通过UserProviderInterface进行身份验证,symfony,Symfony,我正在对自定义用户提供程序使用ldap身份验证。如果一个用户带着cookie从我域中的另一个站点来到我的站点,我想让他们自动登录。我希望我可以从我的登录控制器使用我的UserProviderInterface来实现这一点,但似乎不知道如何实现 任何帮助都将不胜感激 我一直在做一些研究,似乎我需要看看SimplePreAuthenticatorInterface。这似乎是正确的方法吗?我发现这篇文章: 它的长短是 我在services.yml中添加了一个新服务 app.cookie_auth:

我正在对自定义用户提供程序使用ldap身份验证。如果一个用户带着cookie从我域中的另一个站点来到我的站点,我想让他们自动登录。我希望我可以从我的登录控制器使用我的UserProviderInterface来实现这一点,但似乎不知道如何实现

任何帮助都将不胜感激


我一直在做一些研究,似乎我需要看看SimplePreAuthenticatorInterface。这似乎是正确的方法吗?

我发现这篇文章:

它的长短是

我在services.yml中添加了一个新服务

app.cookie_auth:
    class: AppBundle\Security\CookieAuth
我在security.yml中的security/firewall/main中添加了该服务

  guard:
     authenticators:
       - app.cookie_auth
然后我创建了一个新类//src/AppBundle/Security/CookieAuth.php 公共函数getCredentials(请求$Request) {


一切正常。

如果“另一个站点”在同一个应用程序中进行管理,并在
安全中配置了防火墙。yml
足以共享相同的防火墙,让用户同时自动登录。您尝试了什么?您是如何尝试并使用您的UserProviderInterface的?什么不起作用,如果出现任何错误怎么办?我使用了一个guard authenticator,它刚刚起作用。我将发布下面是我的解决方案的详细信息。谢谢大家。
    if($_COOKIE["HelloWorld"] == "HelloWorld") {
        return array("token" => $_COOKIE["HelloWorld"]);
    }
  ...
public function getUser($credentials, UserProviderInterface $userProvider)
{
    $cookie = $credentials['token'];

    // if null, authentication will fail
    // if a User object, checkCredentials() is called
    return $userProvider->loadUserByUsername($cookie);
}