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 - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

2

dist/Index.d.ts

@@ -39,5 +39,5 @@ /**

*/
export declare const connect: (host: string) => Promise<{
export declare const connectToJwt: (host: string) => Promise<{
generateToken: (username: string, password: string) => Promise<JWT>;
validateToken: (token: string) => Promise<boolean>;
}>;

@@ -89,3 +89,3 @@ "use strict";

*/
exports.connect = function (host) { return __awaiter(_this, void 0, void 0, function () {
exports.connectToJwt = function (host) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {

@@ -92,0 +92,0 @@ // try to connect

@@ -64,3 +64,3 @@ import axios from 'axios';

*/
export const connect = async (host: string) => {
export const connectToJwt = async (host: string) => {
// try to connect

@@ -67,0 +67,0 @@ return {

{
"name": "wordpress-jwt-auth",
"version": "1.0.1",
"version": "1.1.0",
"description": "Wordpress JWT authentication",

@@ -5,0 +5,0 @@ "main": "dist/Index.js",

@@ -23,3 +23,3 @@ # Wordpress JWT Auth

### `Authenticate(host, username, password)`
### `connectToJwt(host)`

@@ -29,15 +29,36 @@ Authenticate using JWT

```javascript
import { authenticate } from 'wordpress-jwt-auth';
import { connectToJwt } from 'wordpress-jwt-auth';
authenticate('https://www.myhosting.com/wordpress', 'admin', '123456').then((jwt) => {
console.log(jwt.token);
// generated token
// Promise
connectToJwt('https://www.myhosting.com/wordpress').then((jwtConnection) => {
jwtConnection.generateToken('admin', 'password').then(userConnection) => {
console.log(userConnection.token);
// generated token
jwt.validate().then(validated => {
console.log(validate);
// true
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
```javascript
import { generateToken } from 'wordpress-jwt-auth';
const { token } = generateToken('admin', 'root');
```
### Real use
Deleting a post with id `32` from wordpress using [REST API](https://developer.wordpress.org/rest-api/)

@@ -47,3 +68,3 @@

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

@@ -53,6 +74,7 @@ const WP_URL = 'https://www.mywordpress.com';

const { token } = await authenticate(WP_URL, 'superadmin', '2489cs12mklz');
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);
```
```
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