1

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 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

7 Comments

thanks for answering, seems like its not working for me, it works from curl but then i have to send the u/p with every request, in an ajax request it always gives me authorization error 401, i encoded the username:password with base64
Please try with this wp-api.org/guides/…
I am trying that, but i have a small question: suppose if i login with a regular wordpress login form at /wp-login.php and after successful login is is possible to access this pages like /wp-json/users/me, unfortunately it gives me 401 error no matter i am logged in or not
No you can not use that. You need to pass username and password in each request. I have added on client which used for the to call api.
sorry but sending username/password in each request will not be viable in my website, it will also overload the request by checking for user credentials each time, I was used to jquery and it worked just like simple PHP websites, feels like this whole thing of json-api is complicating simple tasks which was done earlier with couple of lines of code.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.