| 1 |
|
| 2 |
=== JSON API Auth === |
| 3 |
|
| 4 |
Donate link: http://www.parorrey.com |
| 5 |
Tags: json api, api, authenticate user, WordPress user authentication |
| 6 |
Contributors: parorrey |
| 7 |
Stable tag: 2.6.0 |
| 8 |
Requires at least: 3.0.1 |
| 9 |
Tested up to: 5.7 |
| 10 |
Requires PHP: 5.3 |
| 11 |
License: GPLv2 or later |
| 12 |
|
| 13 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 14 |
|
| 15 |
Extends the JSON API Plugin for RESTful user authentication |
| 16 |
|
| 17 |
== Description == |
| 18 |
|
| 19 |
JSON API Auth extends the JSON API Plugin to allow RESTful user authentication. |
| 20 |
|
| 21 |
JSON API Plugin, that is required, was closed on August 7, 2019 from WordPress repository. You can download <a href="https://github.com/PI-Media/json-api">JSON API Plugin</a> from https://github.com/PI-Media/json-api until it is republished and available on WordPress. |
| 22 |
|
| 23 |
Features include: |
| 24 |
|
| 25 |
* Generate Auth Cookie for user authentication |
| 26 |
|
| 27 |
* Validate Auth Cookie |
| 28 |
|
| 29 |
* Get Current User Info |
| 30 |
|
| 31 |
For documentation: See 'Other Notes' tab above for usage examples. |
| 32 |
|
| 33 |
Credits: http://www.parorrey.com/solutions/json-api-auth/ |
| 34 |
|
| 35 |
== Installation == |
| 36 |
|
| 37 |
First you have to install the JSON API for WordPress Plugin (http://wordpress.org/extend/plugins/json-api/installation/). or You can download <a href="https://github.com/PI-Media/json-api">JSON API Plugin</a> from https://github.com/PI-Media/json-api |
| 38 |
|
| 39 |
To install JSON API Auth just follow these steps: |
| 40 |
|
| 41 |
* upload the folder "json-api-auth" to your WordPress plugin folder (/wp-content/plugins) |
| 42 |
|
| 43 |
* activate the plugin through the 'Plugins' menu in WordPress or by using the link provided by the plugin installer |
| 44 |
|
| 45 |
* activate the controller through the JSON API menu found in the WordPress admin center (Settings -> JSON API) |
| 46 |
|
| 47 |
== Screenshots == |
| 48 |
|
| 49 |
1. Call to generate_auth_cookie endpoint using Postman |
| 50 |
2. Call to get_currentuserinfo endpoint using Postman |
| 51 |
3. Call to validate_auth_cookie endpoint using Postman |
| 52 |
|
| 53 |
== Changelog == |
| 54 |
|
| 55 |
|
| 56 |
= 2.6.0 = |
| 57 |
* Updated for wordpress version 5.7 |
| 58 |
|
| 59 |
= 2.5.0 = |
| 60 |
* Updated for wordpress version 5.5.3 |
| 61 |
|
| 62 |
= 2.4.0 = |
| 63 |
|
| 64 |
* Fixed bug in the generate_auth_cookie endpoint. |
| 65 |
|
| 66 |
= 2.3.0 = |
| 67 |
|
| 68 |
* Updated for JSON API Plugin diretory check error and updated action links. |
| 69 |
|
| 70 |
= 2.2.0 = |
| 71 |
|
| 72 |
* Updated for GitHub and settings action links. |
| 73 |
|
| 74 |
= 2.1.0 = |
| 75 |
|
| 76 |
* Updated for WordPress version & added JSON API plugin GitHub link due its closing down on WordPress repository. |
| 77 |
|
| 78 |
= 2.0.0 = |
| 79 |
|
| 80 |
* Updated for wordpress version |
| 81 |
|
| 82 |
|
| 83 |
== Frequently Asked Questions == |
| 84 |
|
| 85 |
Thanks to 'mattberg' who wrote the auth controller (https://github.com/mattberg/wp-json-api-auth) initially. I have added few methods and authored it as a WordPress plugin so that it could easily be searched and installed vis WordPress. |
| 86 |
|
| 87 |
* There are following methods available: validate_auth_cookie, generate_auth_cookie, clear_auth_cookie, get_currentuserinfo |
| 88 |
|
| 89 |
* nonce can be created by calling http://localhost/api/get_nonce/?controller=auth&method=generate_auth_cookie |
| 90 |
|
| 91 |
* You can then use 'nonce' value to generate cookie. http://localhost/api/auth/generate_auth_cookie/?nonce=f4320f4a67&username=Catherine&password=password-here |
| 92 |
|
| 93 |
* Use cookie like this with your other controller calls: http://localhost/api/contoller-name/method-name/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |
| 94 |
|
| 95 |
For instance, you have a new controller 'events' and want to allow users to post new 'event' using 'add_event' method. |
| 96 |
This is how you will call the end point with cookie and post the event with user info: |
| 97 |
|
| 98 |
http://localhost/api/events/add_event/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |
| 99 |
|
| 100 |
If you want sample code how it can be done, check 'JSON API User' plugin https://wordpress.org/plugins/json-api-user/. This Auth plugin is part of JSON API User plugin. |
| 101 |
|
| 102 |
= Method: validate_auth_cookie = |
| 103 |
|
| 104 |
It needs 'cookie' var. |
| 105 |
|
| 106 |
http://localhost/api/auth/validate_auth_cookie/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |
| 107 |
|
| 108 |
|
| 109 |
= Method: generate_auth_cookie = |
| 110 |
|
| 111 |
It needs `username`, `password` vars. `seconds` is optional. |
| 112 |
|
| 113 |
Then generate cookie: http://localhost/api/auth/generate_auth_cookie/?username=john&password=PASSWORD-HERE |
| 114 |
|
| 115 |
Optional 'seconds' var. It provided, generated cookie will be valid for that many seconds, otherwise default is for 14 days. |
| 116 |
|
| 117 |
generate cookie for 1 minute: http://localhost/api/auth/generate_auth_cookie/?username=john&password=PASSWORD-HERE&seconds=60 |
| 118 |
|
| 119 |
60 means 1 minute. |
| 120 |
|
| 121 |
|
| 122 |
= Method: get_currentuserinfo = |
| 123 |
|
| 124 |
It needs 'cookie' var. |
| 125 |
|
| 126 |
http://localhost/api/auth/get_currentuserinfo/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |