Skip to content

Commit 16ae3f6

Browse files
Reworded and simplified the article
1 parent 820f28e commit 16ae3f6

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

security/json_login_setup.rst

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ In this entry, you'll build a JSON endpoint to log in your users. Of course, whe
55
user logs in, you can load your users from anywhere - like the database.
66
See :ref:`security-user-providers` for details.
77

8-
First, enable form login under your firewall:
8+
First, enable the JSON login under your firewall:
99

1010
.. configuration-block::
1111

@@ -19,7 +19,7 @@ First, enable form login under your firewall:
1919
main:
2020
anonymous: ~
2121
json_login:
22-
check_path: login
22+
check_path: /login
2323
2424
.. code-block:: xml
2525
@@ -34,7 +34,7 @@ First, enable form login under your firewall:
3434
<config>
3535
<firewall name="main">
3636
<anonymous />
37-
<json-login check-path="login" />
37+
<json-login check-path="/login" />
3838
</firewall>
3939
</config>
4040
</srv:container>
@@ -47,30 +47,20 @@ First, enable form login under your firewall:
4747
'main' => array(
4848
'anonymous' => null,
4949
'json_login' => array(
50-
'check_path' => 'login',
50+
'check_path' => '/login',
5151
),
5252
),
5353
),
5454
));
5555
5656
.. tip::
5757

58-
The ``check_path`` can also be route names (but cannot have mandatory wildcards - e.g.
58+
The ``check_path`` can also be a route name (but cannot have mandatory wildcards - e.g.
5959
``/login/{foo}`` where ``foo`` has no default value).
6060

61-
Create a new ``SecurityController`` inside a bundle::
62-
63-
// src/AppBundle/Controller/SecurityController.php
64-
namespace AppBundle\Controller;
65-
66-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
67-
68-
class SecurityController extends Controller
69-
{
70-
}
71-
72-
Next, configure the route that you earlier used under your ``json_login``
73-
configuration (``login``):
61+
Now, when a request is made to the ``/login`` URL, the security system initiates
62+
the authentication process. You just need to define anywhere in your application
63+
an empty controller associated with that URL::
7464

7565
.. configuration-block::
7666

@@ -126,20 +116,10 @@ configuration (``login``):
126116
127117
return $collection;
128118
129-
Great!
130-
131-
Don't let this controller confuse you. As you'll see in a moment, when the
132-
user submits the form, the security system automatically handles the form
133-
submission for you. If the user submits an invalid username or password,
134-
this controller reads the form submission error from the security system,
135-
so that it can be displayed back to the user.
136-
137-
In other words the security system itself takes care of checking the submitted
138-
username and password and authenticating the user.
139-
140-
And that's it! When you submit a ``POST`` request to the ``/login`` URL with
141-
the following JSON document as body, the security system will automatically
142-
check the user's credentials and either authenticate the user or throw an error:
119+
Don't let this empty controller confuse you. When you submit a ``POST`` request
120+
to the ``/login`` URL with the following JSON document as body, the security
121+
system automatically handles it and takes care of checking the submitted
122+
username and password and authenticating the user or throwing an error:
143123

144124
.. code-block:: json
145125
@@ -218,5 +198,3 @@ The security configuration should be:
218198
),
219199
),
220200
));
221-
222-
.. _`FOSUserBundle`: https://github.com/FriendsOfSymfony/FOSUserBundle

0 commit comments

Comments
 (0)