Skip to main content
4 of 4
added 332 characters in body

To logout using REST in Drupal 8, you can do a POST to:

https://example.com/user/logout?_format=json&token=logout_token

Use the following headers on your request:

  • Content-type: application/json
  • X-CSRF-Token: csrf_token

The values for logout_token and csrf_token are available in the login response.

Be sure to visit admin/config/services/rest and enable the following for the User resource:

  • methods: POST
  • formats: json
  • authentication: cookie

Earlier versions of Drupal 8

Do a GET on ?q=user/logout

This is noted in the JS D8 REST docs: https://www.drupal.org/docs/8/core/modules/rest/javascript-and-drupal-8-restful-web-services

Although it should not matter, the Content-type may need to be set to application/x-www-form-urlencoded.

Here's an example usage from jDrupal: https://github.com/signalpoint/jDrupal/blob/8.x-1.x/src/includes/rest.inc.js#L113