Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wordpress-jwt-auth

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wordpress-jwt-auth

Wordpress JWT authentication

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by116.67%
Maintainers
1
Weekly downloads
 
Created
Source

Wordpress JWT Auth

travis-badge

JS Wrapper for wp-api-jwt-auth

Installation

Please, make sure that you have:

install this package:

npm install wordpress-jwt-auth

Example

connectToJwt(host)

Authenticate using JWT

import { connectToJwt } from 'wordpress-jwt-auth';

// Promise
connectToJwt('https://www.myhosting.com/wordpress').then((jwtConnection) => {
    jwtConnection.generateToken('admin', 'password').then(userConnection) => {
        console.log(userConnection.token);
        // generated token

        jwtConnection.validate().then(validated => {
            console.log(validate);
            // true
        });
    });
});

// Await/Async
const jwtConnection = await connectToJwt('https://www.myhosting.com/wordpress');
const { token } = await jwtConnection.generateToken('admin', 'password');
console.log(jwtConnection.validate(token));
// true

generateToken(username, password)

You can import generateToken directly from library

import { generateToken } from 'wordpress-jwt-auth';

const { token } = generateToken('admin', 'root');

Real use

Deleting a post with id 32 from wordpress using REST API

import axios from 'axios';
import { connectToJwt } from 'wordpress-jwt-auth';

const WP_URL = 'https://www.mywordpress.com';
const POST_ID_TO_DELETE = 32;

const { generateToken } = await connectToJwt(WP_URL);
const { token } = await generateToken('superadmin', '2489cs12mklz');
const authHeader = { headers: { Authorization: `bearer ${token}` } };

axios.delete(`${WP_URL}/wp-json/wp/v2/posts/${POST_ID_TO_DELETE}`, {}, authHeader);

Keywords

FAQs

Package last updated on 04 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc