Drupal Core version: 8.x-4.x
You need to enable the user login service first thing, this may be accomplished in so many ways, I prefer using REST UI module.
Go to /admin/config/services/rest and enable User Rest resource.
Once enabled it you can go to /admin/config/services/rest/resource/entity%3Auser/edit by clicking on Edit next to the User resource. Make sure to enable the GET method.
Now you have everything setup, you can start using the service by running this command in the terminal or by using any application for curl requests like: Postman and Restlet clients.
NOTE: CSRF Token can be obtained from: /rest/session/token
curl -i -L -X POST \
-H "Content-Type:application/json" \
-H "Accept:application/json" \
-H "X-CSRF-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
-d \
'{
"name": "my_username",
"pass": "my_password"
}' \
'http://SITE-URL/user/login?_format=json'
The return objects are as below:
SUCCESS:
{
"current_user": {
"uid": "1",
"roles": [
"authenticated"
],
"name": "Admin"
},
"csrf_token": "bbbbbbbbbbbbbbbbbbbbbbbbbb",
"logout_token": "ccccccccccccccccccccccccc"
}
FAILURE:
{
"message":"Sorry, unrecognized username or password."
}