• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

I Like Kill Nerds

The blog of Australian Front End / Aurelia Javascript Developer & brewing aficionado Dwayne Charrington // Aurelia.io Core Team member.

  • Home
  • Aurelia 2
  • Aurelia 1
  • About
  • Aurelia 2 Consulting/Freelance Work

How to Get Authentication Working Using the Node WPApi Package

Wordpress · September 30, 2021

If you are working with WordPress version 5 and up, you might be using the REST API. I love the in-built REST API WordPress provides, especially for creating applications on top of WordPress.

The Node WPApi package makes this a breeze, especially when it comes to authentication based actions.

My first test with this package was creating a new post, and I got this error message:

Sorry, you are not allowed to create posts as this user.

I was confused at first because I entered the correct username and password for my WordPress installation. Well, as you will discover, WordPress won’t just allow you to perform authentication-based requests using your standard credentials.

Once you are logged in, you need to go down to the application passwords section and generate a new password in your user profile section.

Once you enter a descriptive label, you will be presented with a randomly generated password. You will not be able to retrieve this, so copy and paste it somewhere. You will then use your currently logged in username as your username value and your newly generated application password as your password (instead of the password you use when you log in).

import WPAPI from 'wpapi';

const wp = new WPAPI({
    endpoint: 'https://mycoolwebsite.com/wp-json',
    username: 'user',
    password: 'lcSd JKgZG w49DE TbqZ A95eM 64HJ3a'
});

This is what your code would look like. I am using my generated application password but my standard username, and it works.

Dwayne

Leave a Reply Cancel reply

0 Comments
Inline Feedbacks
View all comments

Primary Sidebar

Popular

  • How To Get The Hash of A File In Node.js
  • Testing Event Listeners In Jest (Without Using A Library)
  • Which Neural DSP Archetype Plugins Should You Buy?
  • NBN Box Installed Inside of Garage, Where Do You Put The Modem?
  • Smoke Detector Randomly Goes Off Early Hours of The Morning
  • How to Use Neural DSP Archetype Plugins With the Quad Cortex
  • How to Fast Launch Microsoft Flight Simulator 2020 (decrease game loading time)
  • Wild Natural Deodorant Review
  • How To Install Eufy Security Cameras Without Drilling or Using Screws
  • Perfectly Smoked Steak On A Charcoal BBQ Using Indirect Heat

Recent Comments

  • Thebe on How to Remove the My Sites Menu From the WordPress Admin Bar
  • Maccas worker jn the 2000s on Dear McDonald’s: bring back the Warm Cookie Sundae, you cowards
  • Anamika Singh on Testing Event Listeners In Jest (Without Using A Library)
  • Stefan on A List of WordPress Gutenberg Core Blocks
  • pandammonium on A List of WordPress Gutenberg Core Blocks

Copyright © 2022 · Dwayne Charrington · Log in

wpDiscuz