-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Added missing security.yaml config #13418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Renaming more occurrences of `apiKey` to `apiToken`, thanks to symfony#13418 (comment)
Wouldn't this change mean that the user now would have to enter their api token when using the login form? That doesn't look right to me. And inside the authenticator we do not use the user provider at all so for that to make it work this change is not necessary if I do not miss anything. |
Well, there is no login form ;-) This is about the API token. What I'm trying to fix is that at https://symfony.com/doc/current/security/guard_authentication.html#step-3-configure-the-authenticator there are some parts missing (commented out) of
Token authentication works without a user provider? Well, if that's really the case (and you certainly know that better than I do) this PR is obviously obsolete. (Usually I try things out before, but I can't remember the details). So in this case there should be a note that people can delete their user provider (which they still will have, if they are coming from https://symfony.com/doc/current/security.html#guard-authenticators ) |
The authenticator will get the user provider passed to its public function getUser($credentials, UserProviderInterface $userProvider)
{
if (null === $credentials) {
// The token header was empty, authentication fails with HTTP Status
// Code 401 "Unauthorized"
return null;
}
// if a User is returned, checkCredentials() is called
return $this->em->getRepository(User::class)
->findOneBy(['apiToken' => $credentials])
;
} I think this approach was used as we do not load the user by username (which we actually do not know) here. |
So maybe it would be better to have an authentication method that does not only use a token, but also an identifier. |
No, I think that's OK; not having an identifier is the reason for having a token, after all. I'll just drop in a short note somewhere à la "If you're doing it this way, you don't need a user provider". OK? |
Hmm, this is exactly one of the pain points of guards that will be fixed in the experimental authenticator system. As the user provider argument is not nullable, you must have a user provider, even though you don't use it at all (so it can be a completely empty InMemoryUserProvider). As it's so ugly, it's probably best to "hide" it a bit in the docs. So I'm in favor of not adding more examples/text, but instead modify the configuration example in "Step 3) Configure the Authenticator". If we replace the first (also note that with this config, you can use |
Yes, good idea!
You mean inside |
Sorry for failing to react on your questions in this issue @ThomasLandauer.
Yes, alright. But let's add a small comment that explains that "username" is the property configured by Do you want to update this PR, or shall I create a new one based on your changes? |
I hope I got what you mean :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it this way. We show a (more complete) example, and we explain the "weird" behavior of the username property when using user providers.
Thanks for your quick response, @ThomasLandauer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @ThomasLandauer! |
I just copied this over from https://symfony.com/doc/3.4/security/guard_authentication.html - since it probably just got lost somehow. When following the instructions at https://symfony.com/doc/current/security.html , you would still have
property: email
in there.