1
votes

First off, I am new to Symfony, so I don't know the exact functionality of bundles like FOSUserBundle etc., as well as the terminology.


I am looking for a way to use the Symfony security component in a way that enables me to decouple a user's login credentials (say, a login name and a password, maybe the roles) from the actual user meta data (like first name, last name, groups, birth date, etc.).

The idea is that a user can login with different sets of login name/password and still be recognized as the same user (in the end that means, getting the same User object).

To me, this comes especially handy in combination with multiple authentication providers. For example, if I wanted to enable my users to login via an OAuth2 service as an alternative to logging in with their locally-hosted login name/password-combination (like StackExchange does, for instance), how would I do that?


I have read multiple pages of documentation of Symfony, e.g.:

This latter one even says at 1) Create your User Entity, that a password is a field of User.

1
Create 2 models like User and UserCredentials, with 1-to-many relation. Use User to keep your metadata, and UserCredentials for authentication.Alex Blex
That's actually what I did before porting to Symfony. The problem I see here is that Controller::getUser() would return an instance of UserCredentials then, likely leading to confusion since the function name is getUser.paolo

1 Answers

1
votes

I have recently created just that, first I named my classes UserCredentials and UserDitails and because of the confusion of the getUser function i decided to rename UserCredentials to User. I agree with Alex Blex about the relation (manyToOne on the User side). When you decouple your login and metadata you will need to learn how to embed forms or creating your own form models, which is something I am currently working on and you might need to implement callback functions for deleting and updating entities. The more I work on my UserBundle, the more it looks like the FOSUserBundle. There is quite a bit of work of designing it to work well but it's great for learning. If you wish to inspect how the FOSUserBundle works, after you install it, you can find it in the vendor/friendsOfSymfony folder, it might provide a few answers.