I would like to authenticate the user through an API (external user provider) running my integration tests.
my config_test.yml
imports:
- { resource: config.yml }
- { resource: parameters_test.yml }
framework:
test: ~
session:
storage_id: session.storage.mock_file
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: info
After the login (SUCCEED) the next step is ask for user information and I got:
"Full authentication is required to access this resource."
I guess something is happening with the stored session. I am using Redis on dev and prod to store sessions. Mocking sessions on the test environment because of
"Failed to start the session because headers have already been sent by "/path/to/bin/phpunit" at line 2."
Doing it manually is working like a charm.
session.storage.mock_fileuses by default%kernel.cache_dir%/sessionsfor a storing of session's file. Check if this folder is writable for both server user and cli user.'Setting up Permissions' http://symfony.com/doc/current/book/installation.html#configuration-and-setup
Another 2 possible reasons of error:
stateless: trueon your firewall infirewallssection. TheContextListeneris not created and Token is not saved to the session. AnonymousToken is assigned to next request.stateless: trueyou also can haveRememberMeTokeninstead ofAnonymousTokenifremember_mefeature enabled. This token is also not full fledged.UPDATE
Ensure that
intercept_redirectsis false inconfig_test.ymlas it may break all redirects.