humanmade/rest-sessions

Name: rest-sessions

Owner: Human Made

Description: Log in and out of WordPress using the REST API.

Created: 2018-02-06 07:54:32.0

Updated: 2018-04-16 16:22:14.0

Pushed: 2018-02-22 06:04:12.0

Homepage:

Size: 4

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

REST Sessions
Log in and out with cookie authentication.

A Human Made project. Maintained by @rmccue.

Working on a REST API-powered theme, and want to include a login form? You need REST Sessions.

Installation

Activate this plugin.

In order to use the API endpoints, you need to pass a login nonce to the API endpoints. You can get this nonce easily in PHP by calling REST_Sessions\Session_Controller::get_nonce().

Usage

Rather than explicitly logging in or out, the endpoints used by this plugin create or destroy sessions. These are the real session objects used under the hood by WordPress, and this fits better with the resource-based paradigm used by REST.

Create a Session (Log In)

To log in, you create a session. To create a session, send a POST request to /sessions/v0/sessions. You need to include the following parameters (preferably in a JSON body):

On success, this will return a 201 Created status code with a Session resource in the body. Additionally, it will set the authentication cookies for the site.

Destroy the Current Session (Log Out)

To log out, you destroy the current session. To destroy the session, send a DELETE request to /sessions/v0/sessions/current. You need to include the REST API nonce for the current user as the _wpnonce parameter, just like any other authenticated endpoint.

On success, this will return a 200 OK status code with a JSON object containing the following properties in the body:

Session Resource

The Session resource returned from these endpoints is a JSON object containing the following properties:

Additionally, an author link is added pointing to the current user. This link is embeddable.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.