Closed soubok closed 8 years ago
Hello @soubok we fix this bug in version 1.0.6
Thanks, the error does not appear any more, but the getUsername() returns an empty string, should I fill new issue ?
What field your are using for encode token:
$app['security.jwt.encoder']->encode(['name' => $user->getUsername()]);
By default getUsername() from getToken() returns "username" from field "name" .
If your are using custom field in jwt token for send username, your must be configure
$app['security.jwt'] = [
'options' => [
'username_claim' => 'name',
]
];
I use the default field (name)
I also noticed that the public function loadUserByUsername($username)
of the UserProviderInterface
is called with the good value for $username
(when my secure route is called)
ps:
my $app['security.token_storage']->getToken()->getUsername()
returns null, not an empty string
if your need username your must user model and get name from modal.
$token = $app['security.token_storage']->getToken();
if (null !== $token {
$user = $token->getUser();
$username = $user->getUsername();
}
thank you, it works!
And now the last issue for today :)
I try to use the secure
method of Silex\Route\SecurityTrait
(see http://silex.sensiolabs.org/doc/providers/security.html#traits) on my secure route:
$app->get('/admin', function(Request $request) use($app) {
return $app->json('ok', 200);
})->secure('ROLE_ADMIN');
When I load this route, loadUserByUsername
is called twice, once with the right $username
and the second time with null
... more simply:
I cannot use $app['security.authorization_checker']->isGranted('ROLE_ADMIN')
in my route because my loadUserByUsername
function get null
as $username
argument.
Hello, try to use version 1.1.0 we add full capability silex security.
Thanks, it works !
Hello,
I try to get the username on a secure route using:
$app['security.token_storage']->getToken()->getUsername()
and I get the following error:
Except for the secret_key and header_name, security.jwt configuration use the default settings. The secure routes are defined like this:
Version:
Note that
$token->setUsernameClaim($this->options['username_claim']);
is properly called inJWTListener.php:65
Do you need more details, or there is something obvious I am doing wrong ?