wordpress json api and ajax login

2019-08-12 06:00发布

问题:

I am working on a wordpress theme based on AngularJS framework, I already setup WP REST API and it is accessible from the /wp-json, My login form is ajax driven (AngularJS controller) now I am looking for a way to authenticate my users against wordpress back-end, I searched all over docs, it says cookie authentication is applicable in this case. it also talks of sending "nonce" for each parameter but there is no clue on how to send username/password for first time authentication from within ajax request. Does json rest api support sending username/password ? it seems there is no routes to it.

I think i am missing something fundamental/

回答1:

There are three types of authentication are the here is the document for the authentication.

http://wp-api.org/guides/authentication.html

You need to login using basic authentication method then wordpress will automatically set the cookies for the login user and you need not manage the cookie in your end.

PHP Client https://github.com/WP-API/client-php

JS CLient https://github.com/WP-API/client-js