Register / Log in using the Wordpress JSON API

I want to create a mobile application for one Wordpress site. I integrated the wordpress json plugin . I'm not sure where I can find a service for registering a user and logging in. Please advice.

+4
source share
4 answers

To register a user with this , you will specify exactly how to register it in the database by simply naming the URL and adding data to it using the GET Method . Now, to do this from a mobile application, you just need to make an http request to the URL containing all the data necessary for the user. This will show how to make a request with Android.

It's just for user registration, there will be another JSON APi Auth plugin used for user login.

These are the basics, since I have little time when I do this, I will provide complete information and an example. But for now, it will do it.

+3
source

I managed to figure out how to log in and register using the @Salam El-Bannas link , in case someone still needs this here:

To complete the task, you need two plugins:

WordPress JSON API Plugin

and

JSON API User

  • To register users: You need a nonce ID , which will be part of the registration parameters during the GET input (this is provided by the plugins). Read the @Salam El-Bannas link for a better understanding. The methodology that I used in android was that immediately the load on the pages blocks the user interface with the message "Connecting ...", and in the background I get the nonce identifier after it is completed. The UI lock disappears, and the nonce identifier is added to the special non- -changeable EditText field created for the nonce identifier, the user then enters their required credentials, and I confirm that it is valid before connecting to the server using the nonce ID, which I got. the result from the server is JSON, so I can handle the rest in Android code using volley and GSON.

  • For user login: you only need the cookie ID created by the plugin, for example, in my case http://localhost/mylocalhost/my_api_base/user/generate_auth_cookie/?insecure=cool& email=xxx@xdfer.org &password=xxxv678

and the result was this json;

{"status":"ok","cookie":"xxxx|1486130938|Ot6yAX7iU773JnQ2zfE8sdmjt09LhHqDKSYBqtekuha|7fe58a35ab9f260c9bced9148f5cf9ae3ab56c16d7d9ce3b2db7da651d4d937d","cookie_name":"wordpress_logged_in_4132d8131ebbc6760d21627637bd4b20","user":{"id":1,"username":"administrator","nicename":"administrator","email":" xxx@xdfer.org ","url":"","registered":"2016-11-02 17:46:19","displayname":"xxxx","firstname":"","lastname":"","nickname":"xxxxwedds","description":"","capabilities":"","avatar":null}}

then you should read this good tutorial to use the resulting JSON in android (if you are new to Android registration) just use your discretion as well.

It is really really simple and interesting as soon as you follow my process.

+3
source

1. Paste the following code into your function.php files. 2. Verify that the WP-REST-API plugin must be installed on the wordpress site

  add_action( 'rest_api_init', 'register_api_hooks' ); function register_api_hooks() { register_rest_route( 'custom-plugin', '/login/', array( 'methods' => 'GET', 'callback' => 'login', ) ); } function login($request){ $creds = array(); $creds['user_login'] = $request["username"]; $creds['user_password'] = $request["password"]; $creds['remember'] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message(); return $user; } add_action( 'after_setup_theme', 'custom_login' ); 

Then your API will be created as

 http://www.url.com/wp-json/custom-plugin/login?username=xyz&password=xyz 

Try it with Postman. You will get 200 as an answer and user info

+2
source

Check out https://github.com/mattberg/wp-json-api-auth . It will handle user input, but not registration. This works well for me in the native application that I am creating.

0
source

All Articles