Symfony - User authentication using external user database + API

132 Views Asked by At

I need to build a Symfony application where the users are not stored in the local database as Entity: the application uses an external user database located at a separate domain, and I am looking at authentication via API. I can't find any extensive examples about this, not even in the documentation, so I came up with my own implementation which I don't think is good at all.

In my app I created the following:

  • A class User, which implements UserInterface, PasswordAuthenticatedUserInterface
  • My UserAuthenticator class is essentially a standard one
  • My UserProvider is what makes the difference, as it makes an HTTP request to https://externaluserdb.example.com (fake url for dummy purpose) in order to fetch user information, instead of relying on local database.

However, this is where I'm getting confused. I have two approaches in mind, but none of these seem to be secure or good practice at all


APPROACH 1 (must be really wrong)


APPROACH 2
This makes a lot more sense to me, but I am not sure it's good practice as I would be passing the clear password to the third-party service (even though it's https, I'm not sure it's good)

0

There are 0 best solutions below