@@ -5,7 +5,7 @@ In this entry, you'll build a JSON endpoint to log in your users. Of course, whe
5
5
user logs in, you can load your users from anywhere - like the database.
6
6
See :ref: `security-user-providers ` for details.
7
7
8
- First, enable form login under your firewall:
8
+ First, enable the JSON login under your firewall:
9
9
10
10
.. configuration-block ::
11
11
@@ -19,7 +19,7 @@ First, enable form login under your firewall:
19
19
main :
20
20
anonymous : ~
21
21
json_login :
22
- check_path : login
22
+ check_path : / login
23
23
24
24
.. code-block :: xml
25
25
@@ -34,7 +34,7 @@ First, enable form login under your firewall:
34
34
<config >
35
35
<firewall name =" main" >
36
36
<anonymous />
37
- <json-login check-path =" login" />
37
+ <json-login check-path =" / login" />
38
38
</firewall >
39
39
</config >
40
40
</srv : container >
@@ -47,30 +47,20 @@ First, enable form login under your firewall:
47
47
'main' => array(
48
48
'anonymous' => null,
49
49
'json_login' => array(
50
- 'check_path' => 'login',
50
+ 'check_path' => '/ login',
51
51
),
52
52
),
53
53
),
54
54
));
55
55
56
56
.. tip ::
57
57
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.
59
59
``/login/{foo} `` where ``foo `` has no default value).
60
60
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::
74
64
75
65
.. configuration-block ::
76
66
@@ -126,20 +116,10 @@ configuration (``login``):
126
116
127
117
return $collection;
128
118
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:
143
123
144
124
.. code-block :: json
145
125
@@ -218,5 +198,3 @@ The security configuration should be:
218
198
),
219
199
),
220
200
));
221
-
222
- .. _`FOSUserBundle` : https://github.com/FriendsOfSymfony/FOSUserBundle
0 commit comments