0

I need custom Form Login authentication with a third party web service. The problem is that i can't implement UserProvider's method loadUserByUsername($username). Also symfony calls refreshUser(UserInterface $user) on every page load which calls the loadUserByUsername.. My service has only one method that accepts username and password and returns success if they are valid otherwise false. Can i ignore the UserProvider and everything related to it??? Any suggestions.

7
  • 1
    No you cannot ignore user provider however take a look at the guard component. symfony.com/doc/current/security/guard_authentication.html Should be fairly easy to implement your own authenticator.
    – Cerad
    Dec 23, 2016 at 13:52
  • Why "can't" you implement loadUserByUsername($username) ? You are free to implement it as you which as well as refreshUser(UserInterface $user), using a caching service if required. Note the $username is just a keyword which actually means "whatever", you are free to provide whatever you need here to authenticate against your custom service as far as you respect the interface. And as @Cerad said, the new GuardAuthenticator are much simpler to work with. Dec 23, 2016 at 14:08
  • @BorisGuéry - It is not so much that they can't implement loadUserByUsername but rather what they really want is a loadUserByUsernameAndPassword. Which sadly does not exist. I had the same question years ago. And back then, implementing your own authenticator was far more challenging.
    – Cerad
    Dec 23, 2016 at 14:14
  • @Cerad, that's exactly what I wanted to point out. The purpose of the $username here is not to be provided an username as it is used in common username / password combination, but whatever you want to use as it. May it be an e-mail, a token, or even a combination of username and password. Either by providing a custom formatted string recognized by your provider, or by returning a generic / fake User implementation from which you can retrieve the username and use it when implementing the AuthenticationProvider or the newly GuardAuthentication. Dec 23, 2016 at 14:20
  • I don't have access to users by email username or whatever else. I can't provide list of users from the web service so I see no sense of UserProvider. I created custom UserProvider with method loadUserByUsernameAndPassword($username, $password) but symfony calls refreshUser on every page load which calls my web service login function so i move auth login in custom Authenticator but symfony still calls refreshUser...
    – Stasa
    Dec 23, 2016 at 14:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.