Skip to content

Wrong code in UserManager #3

@sintro

Description

@sintro

As I noticed here #2 (comment), UserManager.php has wrong code.
Silex now has another interface with Security provider, and we can not use
app['security']->getToken() anymore like here https://github.com/DaveC49/SimpleUser-Silex2/blob/master/src/SimpleUser/UserManager.php#L741
The correct way now is app['security.token_storage']->getToken() and app['security.token_storage']->setToken()
Btw, the next line in this method is also broken, as it tries to call 'getKey' from AnonymousToken class, which does not have one, as it was renamed to getSecret.
symfony/security-core@5835d04
So, the correct code here will be:

    public function loginAsUser(User $user)
    {
        if (null !== ($current_token = $this->app['security.token_storage']->getToken())) {
            $providerKey = method_exists($current_token, 'getProviderKey') ? $current_token->getProviderKey() : $current_token->getSecret();
            $token = new UsernamePasswordToken($user, null, $providerKey);
            $this->app['security.token_storage']->setToken($token);

            $this->app['user'] = $user;
        }
    }

Also, nothing will work and web-profiler will crash after registration, because there is wrong configuration sample in README to connect this UserManager as custom UserProvider.
Wrong part:
'users' => $app->share(function($app) { return $app['user.manager']; })
Correct:

'users' => function () use ($app) {
	return $app['user.manager'];
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions