Login Drupal User via Rest API


LOGIN USER
/user/login?_format=json

HEADER
Content-Type: application/json

POST
{
  "name": "sammy",
  "pass": "redshift"
}

RESPONSE

{
    "current_user": {
        "uid": "19",
        "name": "sammy"
    },
    "csrf_token": "WpUUGsznDpeaxfqRP95574dwcDkN5mJh-Ml7-xozBaA",
    "logout_token": "8aWM45e-ZHj-g-u2mK1UC52x5uYHDKK7sCipf8GQqE4"
}


Use the CSRF token in your GET, POST, PATCH, DELETE requests by setting the header:
X-CSRF-Token: asda09820380_2238019280dk09n908asjdlkajdaoa
To log out, use the logout token in a POST request. This ends the user's session.
/user/logout?_format=json&token=asdasd09a8sdaslkdasl-asdasdklsajdlkasdjlksj
GET login status:
/user/login_status?_format=json
GET token:
/rest/session/token

 

Snippet Category
DRUPAL