npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wp-federated-login

v0.0.4

Published

Authenticate users through node using WordPress cookies

Downloads

1

Readme

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, So I decided to update the code to make it work and publish a npm package based on that.

NPM package link: https://www.npmjs.com/package/wp-auth

TO INSTALL:

npm i wp-federated-login

TO USE:

In your init:

var wp_auth = require('wp-federated-login').create({
                      wpurl: 'http://my-blog.example',
                      logged_in_key: 'LOGGED_IN_KEY from wp-config.php',
                      logged_in_salt: 'LOGGED_IN_SALT from wp-config.php',
                      mysql_host: 'MySQL host',
                      mysql_user: 'MySQL username',
                      mysql_pass: 'MySQL password',
		              mysql_port: 'MySQL port (defaults to 3306)',
                      mysql_db: 'MySQL database',
                      wp_table_prefix: 'WordPress table prefix (eg. wp_)' });
                      skipAuthentication: Boolean (send true to bypass hash checking and directly get values from SQL DB)
                      debug: Boolean (send true to enable console logs)
                      maxRetries: Number (Number of retries to connect to mysql if connection fails or some error occurs),
                      cacheTimeout: time after which cache will be invalidated and fresh results will be fetched

When you get a HTTP request and you need to verify auth:

wp_auth.checkAuth( req ).on( 'auth', function( auth_is_valid, user_id ) {
    auth_is_valid; // true if the user is logged in, false if they are not
    user_id; // the ID number of the user or 0 if the user is not logged in
} );

To get a usermeta value:

wp_auth.getUserMeta( user_id, 'meta_key (eg. occupation)', function( data ) {
    // data is null if the user doesn't exist or doesn't have the key.
    // Otherwise, it is the value you would get in WordPress (unserialized intelligently)
} );

To get multiple usermetas value at once:

wp_auth.getUserMetas( user_id, 'meta_keys (in array format e.g [ occupation, salary ])', function( data ) {
    // data is null if the user doesn't exist or doesn't have the key.
    // Otherwise, it is the value in array format : [ {occupation: occupationVal }, { salary: salaryVal } ]
} );

To set a usermeta value:

wp_auth.setUserMeta( user_id, 'meta_key (eg. occupation)', 'meta_value (eg. Eating spaghetti)' );

To get a user_id from a usermeta value:

wp_auth.reverseUserMeta( 'meta_key (eg. occupation)', 'meta_value (eg. Eating spaghetti)', function( id ) {
    // id is null if no user could be found with the given meta key value pair
    // Otherwise, it is the ID of the user
    // If multiple users matched, only one will be given
} );