Skip to content

Commit 72f4bbc

Browse files
committed
minor #10467 Fix and improve JSON login docs (dunglas)
This PR was squashed before being merged into the 3.4 branch (closes #10467). Discussion ---------- Fix and improve JSON login docs Since symfony/symfony#22494, it's mandatory to return a valid response in the controller to prevent a 500 error. I've updated the docs accordingly, and added an example of what can be returned. This PR is similar to #9611 (that was right, sorry I just noticed). ping @vincentchalamon Commits ------- 570dce3 Fix and improve JSON login docs
2 parents a7e6bf1 + 570dce3 commit 72f4bbc

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

security/json_login_setup.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ path:
8080
*/
8181
public function loginAction(Request $request)
8282
{
83+
$user = $this->getUser();
84+
85+
return $this->json(array(
86+
'username' => $user->getUsername(),
87+
'roles' => $user->getRoles(),
88+
));
8389
}
8490
}
8591
@@ -117,11 +123,11 @@ path:
117123
118124
return $routes;
119125
120-
Don't let this empty controller confuse you. When you submit a ``POST`` request
121-
to the ``/login`` URL with the following JSON document as the body, the security
122-
system intercepts the requests. It takes care of authenticating the user with
123-
the submitted username and password or triggers an error in case the authentication
124-
process fails:
126+
When you submit a ``POST`` request to the ``/login`` URL with the following JSON document as the body,
127+
the security system intercepts the requests.
128+
It takes care of authenticating the user with the submitted username and password or triggers an error
129+
in case the authentication process fails.
130+
If the authentication is successful, the controller defined earlier will be executed.
125131

126132
.. code-block:: json
127133

0 commit comments

Comments
 (0)