// composer.json
{
"require": {
"php": "^8.0.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^3.6", // v3.6.1
"composer/package-versions-deprecated": "^1.11", // 1.11.99.5
"doctrine/annotations": "^1.13", // 1.13.2
"doctrine/dbal": "^3.3", // 3.3.5
"doctrine/doctrine-bundle": "^2.0", // 2.6.2
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.2.2
"doctrine/orm": "^2.0", // 2.11.2
"knplabs/knp-markdown-bundle": "^1.8", // 1.10.0
"knplabs/knp-time-bundle": "^1.18", // v1.18.0
"pagerfanta/doctrine-orm-adapter": "^3.6", // v3.6.1
"pagerfanta/twig": "^3.6", // v3.6.1
"sensio/framework-extra-bundle": "^6.0", // v6.2.6
"sentry/sentry-symfony": "^4.0", // 4.2.8
"stof/doctrine-extensions-bundle": "^1.5", // v1.7.0
"symfony/asset": "6.0.*", // v6.0.7
"symfony/console": "6.0.*", // v6.0.7
"symfony/dotenv": "6.0.*", // v6.0.5
"symfony/flex": "^2.1", // v2.1.7
"symfony/form": "6.0.*", // v6.0.7
"symfony/framework-bundle": "6.0.*", // v6.0.7
"symfony/mailer": "6.0.*", // v6.0.5
"symfony/monolog-bundle": "^3.0", // v3.7.1
"symfony/property-access": "6.0.*", // v6.0.7
"symfony/property-info": "6.0.*", // v6.0.7
"symfony/proxy-manager-bridge": "6.0.*", // v6.0.6
"symfony/routing": "6.0.*", // v6.0.5
"symfony/runtime": "6.0.*", // v6.0.7
"symfony/security-bundle": "6.0.*", // v6.0.5
"symfony/serializer": "6.0.*", // v6.0.7
"symfony/stopwatch": "6.0.*", // v6.0.5
"symfony/twig-bundle": "6.0.*", // v6.0.3
"symfony/ux-chartjs": "^2.0", // v2.1.0
"symfony/validator": "6.0.*", // v6.0.7
"symfony/webpack-encore-bundle": "^1.7", // v1.14.0
"symfony/yaml": "6.0.*", // v6.0.3
"symfonycasts/verify-email-bundle": "^1.7", // v1.10.0
"twig/extra-bundle": "^2.12|^3.0", // v3.3.8
"twig/string-extra": "^3.3", // v3.3.5
"twig/twig": "^2.12|^3.0" // v3.3.10
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.4.1
"phpunit/phpunit": "^9.5", // 9.5.20
"rector/rector": "^0.12.17", // 0.12.20
"symfony/debug-bundle": "6.0.*", // v6.0.3
"symfony/maker-bundle": "^1.15", // v1.38.0
"symfony/var-dumper": "6.0.*", // v6.0.6
"symfony/web-profiler-bundle": "6.0.*", // v6.0.6
"zenstruck/foundry": "^1.16" // v1.18.0
}
}
19 Comments
Hello everybody, I'm trying to implement security with no user table and authentication authorization all through an API, but I'm a little bit confused about what is the best way to implement it. Firstly I created the user with the make user method and Symfony creates the User class and a UserProvider class, then I check the course and learned about LoginFormAutheticator. I am already getting the response from the API with this piece of code in the class UserProvider implements UserProviderInterface, PasswordUpgraderInterface. But this method should return UserInterface and not a Passport. Do I have to implement the LoginFormAuthenticator instead of this method? What I'm missing is creating the user, the roles and processing the login. The User class created by Symfony implements UserInterface. Maybe is only an issue of filling the methods setUsername and setRoles and I can add there anything I need to store user information. Thanks for your help.
Hey @MDelaCruzPeru
You can use the
LoginFormAuthenticatorif you have a login form or create a custom authenticator to fill in the logic for fetching users through the API. If I recall correctly, on a successful login, you'll need to return an instance ofUserInterface, you can just add a User class to your project, it does not need to be an entity, just a holder for your users' infoYou'll also need that
UserProviderbecause Symfony will use it to reload your user object. You can learn more about Symfony's security here https://symfonycasts.com/screencast/symfony-security - The tutorial it's built on Symfony 5 but all concepts are up to dateCheers!
Hi,
I already had the authenticate method in Symfony 5, however after upgrading to 6 I get this error when a user is not found or types in an incorrect password:
This is the code I use:
Any idea what might cause this? It seems to not like the Exceptions I defined in the UserBadge.
Hey Dirk,
Yeah, the
get()request method does not work with arrays in Symfony 6.x anymore, only with scalar values. You need to useall()instead, e.g. in your case it should be something like this:See a related PR https://github.com/php-translation/symfony-bundle/pull/488 for more context.
Cheers!
Spot on! Works flawlessly now. Many thanks for your quick reply, Victor!
Hey Dirk,
Awesome, thanks for confirming it helped :)
Cheers!
Hello MolloKhan,
Thank you for the quick response.
We only use
http_basic_ldap.It goes wrong when i want to start a session, when we have no
PHP_AUTH_USER.If i turn of
enable_authenticator_managereverything works fine.When I start a session and should get a popup for username, password, i get this error:
This is our services.yaml
And this is our security.yaml
Thanks for your help
Hey Annemieke, sorry for my slow response, but I was on holiday :)
You seem to be trying to inject a User object into a controller's action. Double-check the arguments of your controller
Hi MolloKhan,
Hope you had a nice vacation.
I get errors with every url (in the controller, voter etc.).
Because the
username, password popupdoes not show up while it should when it is a new session.When i turn of
enable_authenticator_managerthe popup does show, you fill in your username and password and everything works fine.Can i send you some code or anything for you to try and replicate this situation?
Thanks in advance.
That's interesting... yea, I think I'd need to see your code. Perhaps you could give me access to your repository?
Hi Diego,
Do do you have some base example of a working ldap authentication program with symfony 6?
I have it working with symfony 5 and with symfony 3 for the last 4 years.
And what code do you need exactly?
Thanks in advance.
With kind regards,
Annemieke
Hey Annemieke-B,
Symfony Docs have some examples about authenticating against an LDAP server, you can check it here: https://symfony.com/doc/current/security/ldap.html - unfortunately, I have never used this before, so can't help with examples, but I hope the official docs help!
Cheers!
I'm afraid I do not have a working example. I'd like to play around with your application so I can debug what's going on, but I'd understand if you cannot share your app's code. I'll ask the team if someone can jump in to help
Hi all,
It goes wrong in HttpBasicAuthenticator class.
Since with a new session i do not have a
PHP_AUTH_USERi will never get a response true.For testing purposes I've added a few lines of code and everything works like a charm:
But now of course i have to find out how to set
PHP_AUTH_USERoutside vendor code.Hey Annemieke, an option would be to create a custom authenticator that extends from
HttpBasicAuthenticatorso you can override thesupports()method and add those linesCheers!
Hi Diego, thanks for the help.
HttpBasicAuthenticator is a final class, so I cannot extend it.
Or did you mean something else?
Greetz!
ps. I think i have to do something in apache virtual hosts.
Ohh, I was not aware of that (personally, I don't like final classes too much :p). What you can do instead is to decorate the
HttpBasicAuthenticatorclass - https://symfony.com/doc/current/service_container/service_decoration.htmlCheers!
Hi Symfony Casts,
Again, great work people, thank you very much for making these videos.
Finally got my employers to invest in its developers and arrange a team account for symfony casts !!!
My question is:
We use ldap for authentication and authorization in symfony 5.4.
This works fine as long as we do not set 'enable_authenticator_manager' to true.
We want to use the LdapAuthenticator class of course, but the code first goes to
HttpBasicAuthenticator.There the support function gives us a false because of course we do not use
PHP_AUTH_USER.If i hack this function and let it always return true, it will get to LdapAuthenticator.
When i do a dump in the AuthenticatorManager class in the constructor of
$this->authenticatorsi get:Thank you very much for your help. Hope to hear from you soon, we are upgrading to sf 6!
Kind regards,
Annemieke Buijs
Hey Annemieke,
Congratulations on convincing your employers! They're not going to regret this ;)
About your problem. When you activate the
enable_authenticator_manager, it enables the new Symfony security system, so you need to adapt your authenticators. Perhaps you already did it, so the next step is to set up the execution order of your custom authenticators by tweaking thesecurity.firewalls.main.custom_authenticatorsconfig option in yoursecurity.yamlfile. Symfony will call the authenticators from top to bottom and will stop calling them as soon as one of them returnstruefrom itssupportsmethodCheers!
"Houston: no signs of life"
Start the conversation!