Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0961128

Browse filesBrowse files
Show the simple example first and then explain the complex use case
1 parent 68bd9a5 commit 0961128
Copy full SHA for 0961128

File tree

1 file changed

+73
-12
lines changed
Filter options

1 file changed

+73
-12
lines changed

‎security/json_login_setup.rst

Copy file name to clipboardExpand all lines: security/json_login_setup.rst
+73-12Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ First, enable form login under your firewall:
2626
main:
2727
anonymous: ~
2828
json_login:
29-
check_path: login
30-
username_path: user.login
31-
password_path: user.password
29+
check_path: login
3230
3331
.. code-block:: xml
3432
@@ -43,7 +41,7 @@ First, enable form login under your firewall:
4341
<config>
4442
<firewall name="main">
4543
<anonymous />
46-
<json-login check-path="login" username-path="user.login" password-path="user.password" />
44+
<json-login check-path="login" />
4745
</firewall>
4846
</config>
4947
</srv:container>
@@ -57,8 +55,6 @@ First, enable form login under your firewall:
5755
'anonymous' => null,
5856
'json_login' => array(
5957
'check_path' => 'login',
60-
'username_path' => 'user.login',
61-
'password_path' => 'user.password',
6258
),
6359
),
6460
),
@@ -155,14 +151,79 @@ check the user's credentials and either authenticate the user or throw an error:
155151
.. code-block:: json
156152
157153
{
158-
"user": {
159-
"login": "dunglas",
160-
"password": "MyPassword"
154+
"login": "dunglas",
155+
"password": "MyPassword"
156+
}
157+
158+
If the JSON document has a different structure, you can specify the path to
159+
access to the user and password properties using the ``username_path`` and
160+
``password_path`` keys (they default respectively to ``username`` and ``password``).
161+
162+
For example, if the JSON document has the following structure:
163+
164+
.. code-block:: json
165+
166+
{
167+
"security":
168+
"credentials": {
169+
"login": "dunglas",
170+
"password": "MyPassword"
171+
}
161172
}
162173
}
163174
164-
You can specify the path to access to the user and password in the JSON document
165-
using the ``username_path`` and the ``password_path`` keys. They default respectively
166-
to ``username`` and ``password``.
175+
The security configuration should be:
176+
177+
.. configuration-block::
178+
179+
.. code-block:: yaml
180+
181+
# app/config/security.yml
182+
security:
183+
# ...
184+
185+
firewalls:
186+
main:
187+
anonymous: ~
188+
json_login:
189+
check_path: login
190+
username_path: security.credentials.login
191+
password_path: security.credentials.password
192+
193+
.. code-block:: xml
194+
195+
<!-- app/config/security.xml -->
196+
<?xml version="1.0" encoding="UTF-8"?>
197+
<srv:container xmlns="http://symfony.com/schema/dic/security"
198+
xmlns:srv="http://symfony.com/schema/dic/services"
199+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
200+
xsi:schemaLocation="http://symfony.com/schema/dic/services
201+
http://symfony.com/schema/dic/services/services-1.0.xsd">
202+
203+
<config>
204+
<firewall name="main">
205+
<anonymous />
206+
<json-login check-path="login"
207+
username-path="security.credentials.login"
208+
password-path="security.credentials.password" />
209+
</firewall>
210+
</config>
211+
</srv:container>
212+
213+
.. code-block:: php
214+
215+
// app/config/security.php
216+
$container->loadFromExtension('security', array(
217+
'firewalls' => array(
218+
'main' => array(
219+
'anonymous' => null,
220+
'json_login' => array(
221+
'check_path' => 'login',
222+
'username_path' => 'security.credentials.login',
223+
'password_path' => 'security.credentials.password',
224+
),
225+
),
226+
),
227+
));
167228
168229
.. _`FOSUserBundle`: https://github.com/FriendsOfSymfony/FOSUserBundle

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.