I just went through this tutorial: http://symfony.com/doc/current/cookbook/security/api_key_authentication.html (including "Storing Authentication in the Session")
It works and authorizes users by an api key and successfully stores authentication in the Session.
But, I've no any ideas how to programmatically authenticate user through that authentication method.
I've tried something like:
$user = new User(
'admin',
null,
['ROLE_ADMIN']
);
$token = new PreAuthenticatedToken($user, null, "secured_area", $user->getRoles());
$this->get("security.token_storage")->setToken($token);
$request = $this->get("request");
$event = new InteractiveLoginEvent($request, $token);
$this->get("event_dispatcher")->dispatch("security.interactive_login", $event);
but it seems like it used wrong authentication provider.
Can please someone tell me what I doing wrong? (:
Updated:
When authentication was done by method above, in session token is stored under "default" firewall.
security:
providers:
api_key_user_provider:
id: api_key_user_provider
firewalls:
dev:
pattern: ^/(_(profiler|wdt|error)|css|images|js)/
security: false
secured_area:
pattern: ^/admin
simple_preauth:
authenticator: apikey_authenticator
default:
anonymous: ~
Why instead of using "secured_area" firewall it uses "default"? How to properly force "secured_area" usage?