我正在使用自定义用户提供程序进行ldap身份验证。如果用户使用我域中其他网站的cookie访问我的网站,我想自动将其登录。我希望我可以使用我的登录控制器中的UserProviderInterface来做到这一点,但似乎无法弄清楚如何。
非常感谢任何帮助。
我一直在做一些看,似乎我需要看看SimplePreAuthenticatorInterface。这看起来像是正确的做法吗?
答案 0 :(得分:0)
我发现这篇文章:
http://symfony.com/doc/current/security/guard_authentication.html
它的长短是......
我在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) {
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);
}
一切正常。