How do I convert an AbstractAuthListener from symfony 2.5 to symfony 2.6 when getToken and setToken signature have changed

27 views Asked by At

Symfony 2.6 deprecated security.context and split it into token_storage and authorization_checker services.

The provided examples in the upgrade docs do fine explaining how to upgrade controllers that use the security.context service, but say little about what to do in the Authentication system itself.

Specifically, prior to 2.6 security.context service had a getToken and setToken function who had a single optional argument of token. The new token_storage service has getToken and setToken functions, but they require a tokenid and a token. The cannonical example documentation for doing custom authentication (see the 2.7 Custom Authentication Docs) still shows passing just a token to setToken, although it is updated to show using the token_storage service.

Has anyone who has upgrade from <=2.5 to >=2.6 successfully implemented custom authentication and if so can you tell where/how I should obtain the necessary tokenId for passing to the setToken and getToken methods?

Example code from pre-2.6 inside of AbstractAuthListener->handle function:

        $previousToken = $this->securityContext->getToken();
        $authToken = $this->authenticationManager->authenticate($token);
        $this->securityContext->setToken($authToken);
        ...// various other code
        catch(\Exception $ex){$this->securityContext->setToken() //clearing security context due to exception during authentication.

post 2.6 getToken shows a required parameter of $tokenId and setToken requires both $tokenId and $token

0

There are 0 answers