Skip to content

Document in memory user extra fields #14928

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions security/user_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ activated), the ``loadUserByUsername()`` method on ``UserRepository`` will be ca
Memory User Provider
--------------------

It's not recommended to use this provider in real applications because of its
limitations and how difficult it is to manage users. It may be useful in application
prototypes and for limited applications that don't store users in databases.
It's not recommended to use this provider because of its limitations to manage users.
It nonetheless may be useful in application prototypes and for specific applications
that don't need to have a complex user modelisation.

This user provider stores all user information in a configuration file,
including their passwords. That's why the first step is to configure how these
Expand Down Expand Up @@ -288,8 +288,14 @@ Now you can configure all the user information in ``config/packages/security.yam
backend_users:
memory:
users:
john_admin: { password: '$2y$13$jxGxc ... IuqDju', roles: ['ROLE_ADMIN'] }
jane_admin: { password: '$2y$13$PFi1I ... rGwXCZ', roles: ['ROLE_ADMIN', 'ROLE_SUPER_ADMIN'] }
john_admin: { password: '$2y$13$jxGxc ... IuqDju', roles: ['ROLE_ADMIN'] }
alice_admin: { password: '$2y$13$AMg7Z ... dFxRBA', roles: ['ROLE_ADMIN'], extra_fields: {'name': 'Alice', 'age': 42}}
jane_admin: { password: '$2y$13$PFi1I ... rGwXCZ', roles: ['ROLE_ADMIN', 'ROLE_SUPER_ADMIN'] }

.. versionadded:: 5.3

The ``extra_fields`` support was introduced in Symfony 5.3.
This allows you to retrieve some user data with ``$user->getExtraFields()['age'];`` having a ``$user`` from the Security layer.

.. caution::

Expand Down