| 1 |
=== JSON API Auth === |
| 2 |
|
| 3 |
Donate link: http://www.parorrey.com |
| 4 |
|
| 5 |
Tags: json api, api, authenticate user, wordpress user authentication |
| 6 |
|
| 7 |
Contributors: parorrey |
| 8 |
|
| 9 |
Stable tag: 1.8 |
| 10 |
|
| 11 |
Requires at least: 3.0.1 |
| 12 |
|
| 13 |
Tested up to: 4.4 |
| 14 |
|
| 15 |
License: GPLv2 or later |
| 16 |
|
| 17 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html |
| 18 |
|
| 19 |
Extends the JSON API Plugin for RESTful user authentication |
| 20 |
|
| 21 |
==Description== |
| 22 |
|
| 23 |
JSON API Auth extends the JSON API Plugin to allow RESTful user authentication. |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
Features include: |
| 28 |
|
| 29 |
* Generate Auth Cookie for user authentication |
| 30 |
|
| 31 |
* Validate Auth Cookie |
| 32 |
|
| 33 |
* Get Current User Info |
| 34 |
|
| 35 |
For documentation: See 'Other Notes' tab above for usage examples. |
| 36 |
|
| 37 |
Credits: http://www.parorrey.com/solutions/json-api-auth/ |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
==Installation== |
| 42 |
|
| 43 |
First you have to install the JSON API for WordPress Plugin (http://wordpress.org/extend/plugins/json-api/installation/). |
| 44 |
|
| 45 |
To install JSON API Auth just follow these steps: |
| 46 |
|
| 47 |
* upload the folder "json-api-auth" to your WordPress plugin folder (/wp-content/plugins) |
| 48 |
|
| 49 |
* activate the plugin through the 'Plugins' menu in WordPress or by using the link provided by the plugin installer |
| 50 |
|
| 51 |
* activate the controller through the JSON API menu found in the WordPress admin center (Settings -> JSON API) |
| 52 |
|
| 53 |
|
| 54 |
== Screenshots == |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
==Changelog== |
| 60 |
|
| 61 |
= 1.8 = |
| 62 |
|
| 63 |
* Updated for WordPress 4.4 version. Made it secure by adding SSL check and adding POST method support, thanks to 'xiffy' for sharing code. |
| 64 |
|
| 65 |
= 1.7 = |
| 66 |
|
| 67 |
* updated for wordpress 4.1.2 version |
| 68 |
|
| 69 |
= 1.6 = |
| 70 |
|
| 71 |
* generate_auth_cookie does not require nonce any more to generate cookie. |
| 72 |
* generate_auth_cookie now also returns 'cookie_name'. |
| 73 |
|
| 74 |
= 1.5.1 = |
| 75 |
|
| 76 |
* Fixed the JSON API Plugin link with protocol |
| 77 |
* Updated notes for documentation. |
| 78 |
|
| 79 |
|
| 80 |
= 1.5 = |
| 81 |
|
| 82 |
* Added the function to authenticate, allow the user (with edit rights) to use JSON API core controllers as well. Thanks `necro_txilok` for the suggestion. |
| 83 |
* Removed `clear_auth_cookie` for not doing what it intends to do, instead `generate_auth_cookie` has been modified to allow setting up auth cookie for any required duration. Just provide the `seconds` var with `nonce`, `username` and `password` to get required cookie. Default time is 14 days. |
| 84 |
* Fixed typos in documentation. |
| 85 |
|
| 86 |
= 1.4 = |
| 87 |
|
| 88 |
* update for WordPress 4.1 |
| 89 |
|
| 90 |
= 1.3 = |
| 91 |
|
| 92 |
* Removed bug for generating cookie |
| 93 |
|
| 94 |
|
| 95 |
= 1.2 = |
| 96 |
|
| 97 |
* Updated plugin description, documentation and few urls |
| 98 |
|
| 99 |
= 1.1 = |
| 100 |
|
| 101 |
* Added clear_auth_cookie() for removing auth cookie. |
| 102 |
|
| 103 |
* Added documentation for the available end points |
| 104 |
|
| 105 |
|
| 106 |
= 1.0 = |
| 107 |
|
| 108 |
* Added the user avatar info for generate_auth_cookie() and get_currentuserinfo() |
| 109 |
|
| 110 |
|
| 111 |
* Updated the FAQs |
| 112 |
|
| 113 |
= 0.1 = |
| 114 |
|
| 115 |
* Initial release. |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
== Upgrade Notice == |
| 120 |
|
| 121 |
= 0.1 = |
| 122 |
|
| 123 |
* Initial release. |
| 124 |
|
| 125 |
|
| 126 |
==Documentation== |
| 127 |
|
| 128 |
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. |
| 129 |
|
| 130 |
|
| 131 |
* There are following methods available: validate_auth_cookie, generate_auth_cookie, clear_auth_cookie, get_currentuserinfo |
| 132 |
|
| 133 |
* nonce can be created by calling http://localhost/api/get_nonce/?controller=auth&method=generate_auth_cookie |
| 134 |
|
| 135 |
* You can then use 'nonce' value to generate cookie. http://localhost/api/auth/generate_auth_cookie/?nonce=f4320f4a67&username=Catherine&password=password-here |
| 136 |
|
| 137 |
* Use cookie like this with your other controller calls: http://localhost/api/contoller-name/method-name/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |
| 138 |
|
| 139 |
For instance, you have a new controller 'events' and want to allow users to post new 'event' using 'add_event' method. |
| 140 |
This is how you will call the end point with cookie and post the event with user info: |
| 141 |
|
| 142 |
http://localhost/api/events/add_event/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |
| 143 |
|
| 144 |
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. |
| 145 |
|
| 146 |
= Method: validate_auth_cookie = |
| 147 |
|
| 148 |
It needs 'cookie' var. |
| 149 |
|
| 150 |
http://localhost/api/auth/validate_auth_cookie/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |
| 151 |
|
| 152 |
|
| 153 |
= Method: generate_auth_cookie = |
| 154 |
|
| 155 |
It needs `username`, `password` vars. `seconds` is optional. |
| 156 |
|
| 157 |
Then generate cookie: http://localhost/api/auth/generate_auth_cookie/?username=john&password=PASSWORD-HERE |
| 158 |
|
| 159 |
Optional 'seconds' var. It provided, generated cookie will be valid for that many seconds, otherwise default is for 14 days. |
| 160 |
|
| 161 |
generate cookie for 1 minute: http://localhost/api/auth/generate_auth_cookie/?username=john&password=PASSWORD-HERE&seconds=60 |
| 162 |
|
| 163 |
60 means 1 minute. |
| 164 |
|
| 165 |
|
| 166 |
= Method: get_currentuserinfo = |
| 167 |
|
| 168 |
It needs 'cookie' var. |
| 169 |
|
| 170 |
http://localhost/api/auth/get_currentuserinfo/?cookie=Catherine|1392018917|3ad7b9f1c5c2cccb569c8a82119ca4fd |