HWIOAuthBundle是在Symfony2项目中进行社交登录的作曲家乐曲:
https://github.com/hwi/HWIOAuthBundle
Symfony2文档给出了在功能测试中如何模拟认证的示例:
http://symfony.com/doc/current/cookbook/testing/simulating_authentication.html
虽然我没有成功地让这两个人在一起工作,Symfony2安全系统表示有一个非匿名用户,但我的Controllers中的getUser()返回null.
任何人都有这样的成功,或者有一些关于如何最好地调试或实现的指针?
使用:
Symfony2 – 2.6.3
> HWIOAuthBundle – dev-master – 309d802f8de9f39e30851a145a7fc0de69b94076
use Liip\FunctionalTestBundle\Test\WebTestCase; use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken; use HWI\Bundle\OAuthBundle\Security\Core\User\OAuthUser; class ControllerTest extends WebTestCase { public function testSecurity() { $client = static::createClient(); $token = new OAuthToken('test',array( 'ROLE_USER','ROLE_OAUTH_USER' )); $user = new OAuthUser('test@test.com'); $token->setUser($user); $session = $client->getContainer()->get('session'); $session->set('_security_name_of_your_firewall',serialize($token)); $session->save(); $cookie = new Cookie($session->getName(),$session->getId()); $client->getCookieJar()->set($cookie); // $client now acts as authenticated client