I am following this guide http://symfony.com/doc/current/cookbook/security/api_key_authentication.html to do the authentication by API KEY.
After calling the last method Authentication token I am able to login a user in, but it doesn't keep the sessions.
return new PreAuthenticatedToken(
$user,
$apiKey,
$providerKey,
$user->getRoles()
);
I also tried to do the authentication using this following:
$user = new User("Test", null, array("ROLE_USER"));
$token = new UsernamePasswordToken($user, null, 'secured_area', $user->getRoles());
$this->get('security.context')->setToken($token);
$this->get('session')->set('_security_secured_area',serialize($token));
Both cases I am only able to log a user in for a single page, not for all project.
Security is like the guide:
firewalls:
secured_area:
pattern: ^/testproject
stateless: true
simple_preauth:
authenticator: apikey_authenticator
Thanks
[update]
$user = new ApiKeyUserProvider();
$user = $user->loadUserByUsername("111111");
$apiKeyProvider = $this->get('apikey_authenticator');
$token = $apiKeyProvider->authenticateToken("111111",$user);
$this->get('security.context')->setToken($token);
$this->get('session')->set('_security_secured_area',serialize($token));
loadUserByUsername is like symfony guide.
Thanks
PreAuthenticatedToken
Rather thanUsernamePasswordToken
– Chase