Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df08df7

Browse files
Initial setup complete
1 parent 59ba388 commit df08df7

4 files changed

Lines changed: 824 additions & 2 deletions

File tree

README.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# node-wp-authenticator
2-
Authenticate users through node using WordPress cookies
1+
This repo is forked from Nightgunner5/node-wordpress-auth. Since The original project is not working on new node versions and is not maintained by the original author anymore I decided to update the code to make it work and publish a npm package based on that.
2+
3+
TO INSTALL:
4+
===========
5+
npm install wp-authenticator
6+
7+
TO USE:
8+
=======
9+
In your init:
10+
var wp_auth = require('wp-authenticator').create({
11+
wpurl: 'http://my-blog.example',
12+
logged_in_key: 'LOGGED_IN_KEY from wp-config.php',
13+
logged_in_salt: 'LOGGED_IN_SALT from wp-config.php',
14+
mysql_host: 'MySQL host',
15+
mysql_user: 'MySQL username',
16+
mysql_pass: 'MySQL password',
17+
mysql_db: 'MySQL database',
18+
wp_table_prefix: 'WordPress table prefix (eg. wp_)' });
19+
20+
When you get a HTTP request and you need to verify auth:
21+
22+
wp_auth.checkAuth( req ).on( 'auth', function( auth_is_valid, user_id ) {
23+
auth_is_valid; // true if the user is logged in, false if they are not
24+
user_id; // the ID number of the user or 0 if the user is not logged in
25+
} );
26+
27+
To get a usermeta value:
28+
29+
wp_auth.getUserMeta( user_id, 'meta_key (eg. occupation)', function( data ) {
30+
// data is null if the user doesn't exist or doesn't have the key.
31+
// Otherwise, it is the value you would get in WordPress (unserialized intelligently)
32+
} );
33+
34+
To set a usermeta value:
35+
36+
wp_auth.setUserMeta( user_id, 'meta_key (eg. occupation)', 'meta_value (eg. Eating spaghetti)' );
37+
38+
To get a user_id from a usermeta value:
39+
40+
wp_auth.reverseUserMeta( 'meta_key (eg. occupation)', 'meta_value (eg. Eating spaghetti)', function( id ) {
41+
// id is null if no user could be found with the given meta key value pair
42+
// Otherwise, it is the ID of the user
43+
// If multiple users matched, only one will be given
44+
} );

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "wp-authenticator",
3+
"version": "1.0.0",
4+
"description": "Authenticate users through node using WordPress cookies",
5+
"main": "wp-auth.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/akashkaushik33/node-wp-authenticator.git"
12+
},
13+
"keywords": [
14+
"node",
15+
"wordpress",
16+
"cokkies",
17+
"auth",
18+
"authentication",
19+
"node-wordpress",
20+
"node-wp"
21+
],
22+
"author": "Akash Kaushik <[email protected]>",
23+
"license": "MIT",
24+
"bugs": {
25+
"url": "https://github.com/akashkaushik33/node-wp-authenticator/issues"
26+
},
27+
"homepage": "https://github.com/akashkaushik33/node-wp-authenticator#readme",
28+
"engines": {
29+
"node": ">=8.0"
30+
},
31+
"dependencies": {
32+
"mysql2": "^2.1.0"
33+
}
34+
}

0 commit comments

Comments
 (0)