├── .gitignore ├── .npmignore ├── .travis.yml ├── .vscode └── launch.json ├── CHANGELOG.md ├── LICENSE ├── README.md ├── dist ├── Index.d.ts └── Index.js ├── lib └── Index.ts ├── package-lock.json ├── package.json ├── tsconfig.json └── tslint.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | **/*.js.map 3 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "8.1.2" 4 | script: 5 | - npm run lint 6 | - npm run build 7 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible Node.js debug attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Debug", 11 | "program": "${workspaceRoot}/lib/Index.ts", 12 | "outFiles": [ 13 | "${workspaceRoot}/dist/Index.js" 14 | ], 15 | "cwd": "${workspaceRoot}", 16 | "sourceMaps": true 17 | }, 18 | { 19 | "type": "node", 20 | "request": "attach", 21 | "name": "Attach to Process", 22 | "port": 5858 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 1.1.1 - 4 - July - 2017 4 | 5 | - extended jsdoc for `generateToken` function 6 | - `connectToJWT` throws an error if host doesn't exists 7 | - `generateToken` throws different error for non-exists host and if authentication failed 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Daniel Derevjanik 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Wordpress JWT Auth 2 | 3 | ![travis-badge](https://travis-ci.org/dderevjanik/wordpress-jwt-auth.svg?branch=master) 4 | 5 | JS Wrapper for [wp-api-jwt-auth](https://github.com/Tmeister/wp-api-jwt-auth) 6 | 7 | ## Installation 8 | 9 | Please, make sure that you have: 10 | 11 | - installed [wp-api-jwt-auth](https://github.com/Tmeister/wp-api-jwt-auth) and enabled on your wp site 12 | - enabled [HTTP Authorization Header](https://github.com/Tmeister/wp-api-jwt-auth#eable-php-http-authorization-header) 13 | - configurated [Secret Key](https://github.com/Tmeister/wp-api-jwt-auth#configurate-the-secret-key) and [CORs Support](https://github.com/Tmeister/wp-api-jwt-auth#configurate-cors-support) 14 | 15 | install this package: 16 | 17 | ```bash 18 | npm install wordpress-jwt-auth 19 | ``` 20 | 21 | ## Example 22 | 23 | ### `connectToJwt(host)` 24 | 25 | Authenticate using JWT 26 | 27 | ```javascript 28 | import { connectToJwt } from 'wordpress-jwt-auth'; 29 | 30 | // Promise 31 | connectToJwt('https://www.myhosting.com/wordpress').then((jwtConnection) => { 32 | jwtConnection.generateToken('admin', 'password').then(userConnection) => { 33 | console.log(userConnection.token); 34 | // generated token 35 | 36 | jwtConnection.validate().then(validated => { 37 | console.log(validate); 38 | // true 39 | }); 40 | }); 41 | }); 42 | 43 | // Await/Async 44 | const jwtConnection = await connectToJwt('https://www.myhosting.com/wordpress'); 45 | const { token } = await jwtConnection.generateToken('admin', 'password'); 46 | console.log(jwtConnection.validate(token)); 47 | // true 48 | ``` 49 | 50 | ### `generateToken(username, password)` 51 | 52 | You can import `generateToken` directly from library 53 | 54 | ```javascript 55 | import { generateToken } from 'wordpress-jwt-auth'; 56 | 57 | const { token } = generateToken('admin', 'root'); 58 | ``` 59 | 60 | ### Real use 61 | 62 | Deleting a post with id `32` from wordpress using [REST API](https://developer.wordpress.org/rest-api/) 63 | 64 | ```javascript 65 | import axios from 'axios'; 66 | import { connectToJwt } from 'wordpress-jwt-auth'; 67 | 68 | const WP_URL = 'https://www.mywordpress.com'; 69 | const POST_ID_TO_DELETE = 32; 70 | 71 | const { generateToken } = await connectToJwt(WP_URL); 72 | const { token } = await generateToken('superadmin', '2489cs12mklz'); 73 | const authHeader = { headers: { Authorization: `bearer ${token}` } }; 74 | 75 | axios.delete(`${WP_URL}/wp-json/wp/v2/posts/${POST_ID_TO_DELETE}`, {}, authHeader); 76 | ``` -------------------------------------------------------------------------------- /dist/Index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * JWT Response after successfully authenticated user 3 | */ 4 | export interface JWT { 5 | /** 6 | * JWT Token used in every request 7 | */ 8 | token: string; 9 | /** 10 | * User email 11 | */ 12 | user_email: string; 13 | /** 14 | * User full name 15 | */ 16 | user_nicename: string; 17 | /** 18 | * Displayed username 19 | */ 20 | user_display_name: string; 21 | } 22 | /** 23 | * Authenticate user 24 | * @param host - host URL 25 | * @param username - user's name used to login 26 | * @param password - user's password used to login 27 | * @throws {CannotAuthenticate} 28 | */ 29 | export declare const generateToken: (host: string, username: string, password: string) => Promise; 30 | /** 31 | * Validate token 32 | * @param host - host URL 33 | * @param token - token to validate 34 | * @returns true if token is successfully validated 35 | */ 36 | export declare const validateToken: (host: string, token: string) => Promise; 37 | /** 38 | * Connect to wordpress jwt API 39 | * @param host - url to wordpress 40 | * @throws {CannotConnect} 41 | */ 42 | export declare const connectToJwt: (host: string) => Promise<{ 43 | generateToken: (username: string, password: string) => Promise; 44 | validateToken: (token: string) => Promise; 45 | }>; 46 | -------------------------------------------------------------------------------- /dist/Index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 3 | return new (P || (P = Promise))(function (resolve, reject) { 4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } 7 | step((generator = generator.apply(thisArg, _arguments || [])).next()); 8 | }); 9 | }; 10 | var __generator = (this && this.__generator) || function (thisArg, body) { 11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; 12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 13 | function verb(n) { return function (v) { return step([n, v]); }; } 14 | function step(op) { 15 | if (f) throw new TypeError("Generator is already executing."); 16 | while (_) try { 17 | if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; 18 | if (y = 0, t) op = [0, t.value]; 19 | switch (op[0]) { 20 | case 0: case 1: t = op; break; 21 | case 4: _.label++; return { value: op[1], done: false }; 22 | case 5: _.label++; y = op[1]; op = [0]; continue; 23 | case 7: op = _.ops.pop(); _.trys.pop(); continue; 24 | default: 25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 29 | if (t[2]) _.ops.pop(); 30 | _.trys.pop(); continue; 31 | } 32 | op = body.call(thisArg, _); 33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 35 | } 36 | }; 37 | var _this = this; 38 | Object.defineProperty(exports, "__esModule", { value: true }); 39 | var axios_1 = require("axios"); 40 | var JWT_ENDPOINT = '/wp-json/jwt-auth/v1/'; 41 | /** 42 | * Authenticate user 43 | * @param host - host URL 44 | * @param username - user's name used to login 45 | * @param password - user's password used to login 46 | * @throws {CannotAuthenticate} 47 | */ 48 | exports.generateToken = function (host, username, password) { return __awaiter(_this, void 0, void 0, function () { 49 | var endPoint, response; 50 | return __generator(this, function (_a) { 51 | switch (_a.label) { 52 | case 0: 53 | endPoint = host + JWT_ENDPOINT; 54 | return [4 /*yield*/, axios_1.default.post(endPoint + 'token', { username: username, password: password })]; 55 | case 1: 56 | response = _a.sent(); 57 | switch (response.status) { 58 | case 403: throw new Error('CannotAuthenticate: Bad username or password'); 59 | case 404: throw new Error("CannotAuthenticate: Page doesn't exists, make sure JWT is installed"); 60 | } 61 | return [2 /*return*/, response.data]; 62 | } 63 | }); 64 | }); }; 65 | /** 66 | * Validate token 67 | * @param host - host URL 68 | * @param token - token to validate 69 | * @returns true if token is successfully validated 70 | */ 71 | exports.validateToken = function (host, token) { return __awaiter(_this, void 0, void 0, function () { 72 | var endPoint, authHeader, response; 73 | return __generator(this, function (_a) { 74 | switch (_a.label) { 75 | case 0: 76 | endPoint = host + JWT_ENDPOINT; 77 | authHeader = { headers: { Authorization: 'bearer ' + token } }; 78 | return [4 /*yield*/, axios_1.default.post(endPoint + 'validate', {}, authHeader)]; 79 | case 1: 80 | response = _a.sent(); 81 | if (response.status === 200) { 82 | return [2 /*return*/, true]; 83 | } 84 | return [2 /*return*/, false]; 85 | } 86 | }); 87 | }); }; 88 | /** 89 | * Connect to wordpress jwt API 90 | * @param host - url to wordpress 91 | * @throws {CannotConnect} 92 | */ 93 | exports.connectToJwt = function (host) { return __awaiter(_this, void 0, void 0, function () { 94 | var response; 95 | return __generator(this, function (_a) { 96 | switch (_a.label) { 97 | case 0: return [4 /*yield*/, axios_1.default.post(host + "/" + JWT_ENDPOINT + "/token")]; 98 | case 1: 99 | response = _a.sent(); 100 | if (response.status === 404) { 101 | throw new Error('CannotConnect: bad host or JWT is not installed'); 102 | } 103 | return [2 /*return*/, { 104 | /** 105 | * Authenticate user 106 | * @param host - host URL 107 | * @param username - user's name used to login 108 | * @param password - user's password used to login 109 | * @throws {CannotAuthenticate} 110 | */ 111 | generateToken: function (username, password) { return exports.generateToken(host, username, password); }, 112 | /** 113 | * Validate token 114 | * @param token - token to validate 115 | * @returns true if token is successfully validated 116 | */ 117 | validateToken: function (token) { return exports.validateToken(host, token); }, 118 | }]; 119 | } 120 | }); 121 | }); }; 122 | //# sourceMappingURL=Index.js.map -------------------------------------------------------------------------------- /lib/Index.ts: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | const JWT_ENDPOINT = '/wp-json/jwt-auth/v1/'; 4 | 5 | /** 6 | * JWT Response after successfully authenticated user 7 | */ 8 | export interface JWT { 9 | /** 10 | * JWT Token used in every request 11 | */ 12 | token: string; 13 | 14 | /** 15 | * User email 16 | */ 17 | user_email: string; 18 | 19 | /** 20 | * User full name 21 | */ 22 | user_nicename: string; 23 | 24 | /** 25 | * Displayed username 26 | */ 27 | user_display_name: string; 28 | } 29 | 30 | /** 31 | * Authenticate user 32 | * @param host - host URL 33 | * @param username - user's name used to login 34 | * @param password - user's password used to login 35 | * @throws {CannotAuthenticate} 36 | */ 37 | export const generateToken = async (host: string, username: string, password: string): Promise => { 38 | const endPoint = host + JWT_ENDPOINT; 39 | const response = await axios.post(endPoint + 'token', { username, password }); 40 | switch (response.status) { 41 | case 403: throw new Error('CannotAuthenticate: Bad username or password'); 42 | case 404: throw new Error(`CannotAuthenticate: Page doesn\'t exists, make sure JWT is installed`); 43 | } 44 | 45 | return response.data as JWT; 46 | }; 47 | 48 | /** 49 | * Validate token 50 | * @param host - host URL 51 | * @param token - token to validate 52 | * @returns true if token is successfully validated 53 | */ 54 | export const validateToken = async (host: string, token: string): Promise => { 55 | const endPoint = host + JWT_ENDPOINT; 56 | const authHeader = { headers: { Authorization: 'bearer ' + token } }; 57 | const response = await axios.post(endPoint + 'validate', {}, authHeader); 58 | if (response.status === 200) { 59 | return true; 60 | } 61 | return false; 62 | }; 63 | 64 | /** 65 | * Connect to wordpress jwt API 66 | * @param host - url to wordpress 67 | * @throws {CannotConnect} 68 | */ 69 | export const connectToJwt = async (host: string) => { 70 | const response = await axios.post(`${host}/${JWT_ENDPOINT}/token`); 71 | if (response.status === 404) { 72 | throw new Error('CannotConnect: bad host or JWT is not installed'); 73 | } 74 | 75 | return { 76 | /** 77 | * Authenticate user 78 | * @param host - host URL 79 | * @param username - user's name used to login 80 | * @param password - user's password used to login 81 | * @throws {CannotAuthenticate} 82 | */ 83 | generateToken: (username: string, password: string) => generateToken(host, username, password), 84 | 85 | /** 86 | * Validate token 87 | * @param token - token to validate 88 | * @returns true if token is successfully validated 89 | */ 90 | validateToken: (token: string) => validateToken(host, token), 91 | }; 92 | }; 93 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wordpress-jwt-auth", 3 | "version": "1.0.0", 4 | "lockfileVersion": 1, 5 | "dependencies": { 6 | "ansi-regex": { 7 | "version": "2.1.1", 8 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", 9 | "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", 10 | "dev": true 11 | }, 12 | "ansi-styles": { 13 | "version": "2.2.1", 14 | "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", 15 | "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", 16 | "dev": true 17 | }, 18 | "axios": { 19 | "version": "0.16.2", 20 | "resolved": "https://registry.npmjs.org/axios/-/axios-0.16.2.tgz", 21 | "integrity": "sha1-uk+S8XFn37q0CYN4VFS5rBScPG0=" 22 | }, 23 | "babel-code-frame": { 24 | "version": "6.22.0", 25 | "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.22.0.tgz", 26 | "integrity": "sha1-AnYgvuVnqIwyVhV05/0IAdMxGOQ=", 27 | "dev": true 28 | }, 29 | "balanced-match": { 30 | "version": "1.0.0", 31 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 32 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", 33 | "dev": true 34 | }, 35 | "brace-expansion": { 36 | "version": "1.1.8", 37 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz", 38 | "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=", 39 | "dev": true 40 | }, 41 | "chalk": { 42 | "version": "1.1.3", 43 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", 44 | "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", 45 | "dev": true 46 | }, 47 | "colors": { 48 | "version": "1.1.2", 49 | "resolved": "https://registry.npmjs.org/colors/-/colors-1.1.2.tgz", 50 | "integrity": "sha1-FopHAXVran9RoSzgyXv6KMCE7WM=", 51 | "dev": true 52 | }, 53 | "concat-map": { 54 | "version": "0.0.1", 55 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 56 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", 57 | "dev": true 58 | }, 59 | "debug": { 60 | "version": "2.6.8", 61 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", 62 | "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=" 63 | }, 64 | "diff": { 65 | "version": "3.2.0", 66 | "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz", 67 | "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=", 68 | "dev": true 69 | }, 70 | "escape-string-regexp": { 71 | "version": "1.0.5", 72 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 73 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", 74 | "dev": true 75 | }, 76 | "esutils": { 77 | "version": "2.0.2", 78 | "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.2.tgz", 79 | "integrity": "sha1-Cr9PHKpbyx96nYrMbepPqqBLrJs=", 80 | "dev": true 81 | }, 82 | "findup-sync": { 83 | "version": "0.3.0", 84 | "resolved": "https://registry.npmjs.org/findup-sync/-/findup-sync-0.3.0.tgz", 85 | "integrity": "sha1-N5MKpdgWt3fANEXhlmzGeQpMCxY=", 86 | "dev": true, 87 | "dependencies": { 88 | "glob": { 89 | "version": "5.0.15", 90 | "resolved": "https://registry.npmjs.org/glob/-/glob-5.0.15.tgz", 91 | "integrity": "sha1-G8k2ueAvSmA/zCIuz3Yz0wuLk7E=", 92 | "dev": true 93 | } 94 | } 95 | }, 96 | "follow-redirects": { 97 | "version": "1.2.4", 98 | "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.2.4.tgz", 99 | "integrity": "sha512-Suw6KewLV2hReSyEOeql+UUkBVyiBm3ok1VPrVFRZnQInWpdoZbbiG5i8aJVSjTr0yQ4Ava0Sh6/joCg1Brdqw==" 100 | }, 101 | "fs.realpath": { 102 | "version": "1.0.0", 103 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 104 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", 105 | "dev": true 106 | }, 107 | "glob": { 108 | "version": "7.1.2", 109 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", 110 | "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", 111 | "dev": true 112 | }, 113 | "has-ansi": { 114 | "version": "2.0.0", 115 | "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", 116 | "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", 117 | "dev": true 118 | }, 119 | "inflight": { 120 | "version": "1.0.6", 121 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 122 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 123 | "dev": true 124 | }, 125 | "inherits": { 126 | "version": "2.0.3", 127 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 128 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", 129 | "dev": true 130 | }, 131 | "is-buffer": { 132 | "version": "1.1.5", 133 | "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.5.tgz", 134 | "integrity": "sha1-Hzsm72E7IUuIy8ojzGwB2Hlh7sw=" 135 | }, 136 | "js-tokens": { 137 | "version": "3.0.1", 138 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.1.tgz", 139 | "integrity": "sha1-COnxMkhKLEWjCQfp3E1VZ7fxFNc=", 140 | "dev": true 141 | }, 142 | "minimatch": { 143 | "version": "3.0.4", 144 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 145 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 146 | "dev": true 147 | }, 148 | "minimist": { 149 | "version": "0.0.10", 150 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz", 151 | "integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=", 152 | "dev": true 153 | }, 154 | "ms": { 155 | "version": "2.0.0", 156 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 157 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" 158 | }, 159 | "once": { 160 | "version": "1.4.0", 161 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 162 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 163 | "dev": true 164 | }, 165 | "optimist": { 166 | "version": "0.6.1", 167 | "resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz", 168 | "integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=", 169 | "dev": true 170 | }, 171 | "path-is-absolute": { 172 | "version": "1.0.1", 173 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 174 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", 175 | "dev": true 176 | }, 177 | "path-parse": { 178 | "version": "1.0.5", 179 | "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", 180 | "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", 181 | "dev": true 182 | }, 183 | "resolve": { 184 | "version": "1.3.3", 185 | "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.3.3.tgz", 186 | "integrity": "sha1-ZVkHw0aahoDcLeOidaj91paR8OU=", 187 | "dev": true 188 | }, 189 | "strip-ansi": { 190 | "version": "3.0.1", 191 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", 192 | "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", 193 | "dev": true 194 | }, 195 | "supports-color": { 196 | "version": "2.0.0", 197 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", 198 | "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", 199 | "dev": true 200 | }, 201 | "ts-lint": { 202 | "version": "4.5.1", 203 | "resolved": "https://registry.npmjs.org/ts-lint/-/ts-lint-4.5.1.tgz", 204 | "integrity": "sha1-nCK3t7hitnMk3RvSE6hFwDp/uMA=", 205 | "dev": true 206 | }, 207 | "tsutils": { 208 | "version": "1.9.1", 209 | "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-1.9.1.tgz", 210 | "integrity": "sha1-ufmrROVa+WgYMdXyjQrur1x1DLA=", 211 | "dev": true 212 | }, 213 | "typescript": { 214 | "version": "2.4.1", 215 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-2.4.1.tgz", 216 | "integrity": "sha1-w8yxbdqgsjFN4DHn5v7onlujRrw=", 217 | "dev": true 218 | }, 219 | "wordwrap": { 220 | "version": "0.0.3", 221 | "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz", 222 | "integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=", 223 | "dev": true 224 | }, 225 | "wrappy": { 226 | "version": "1.0.2", 227 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 228 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", 229 | "dev": true 230 | } 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wordpress-jwt-auth", 3 | "version": "1.1.1", 4 | "description": "Wordpress JWT authentication", 5 | "main": "dist/Index.js", 6 | "homepage": "https://github.com/dderevjanik/wordpress-jwt-auth", 7 | "author": { 8 | "name": "Daniel Derevjanik", 9 | "email": "daniel.derevjanik@gmail.com" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/dderevjanik/wordpress-jwt-auth.git" 14 | }, 15 | "keywords": [ 16 | "wordpress", 17 | "api", 18 | "wordpress-jwt", 19 | "wordpress-auth", 20 | "wordpress-jwt-auth", 21 | "typescript" 22 | ], 23 | "typescript": { 24 | "definition": "dist/Index.d.ts" 25 | }, 26 | "types": "dist/Index.d.ts", 27 | "typings": "dist/Index.d.ts", 28 | "scripts": { 29 | "test": "echo \"Error: no test specified\" && exit 1", 30 | "dev": "tsc --watch", 31 | "build": "tsc", 32 | "lint": "tslint -c tslint.json --fix 'lib/**/*.ts'" 33 | }, 34 | "license": "ISC", 35 | "devDependencies": { 36 | "ts-lint": "^4.5.1", 37 | "typescript": "^2.4.1" 38 | }, 39 | "dependencies": { 40 | "axios": "^0.16.2" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'. */ 6 | "lib": [ 7 | "es2015" 8 | ], /* Specify library files to be included in the compilation: */ 9 | // "allowJs": true, /* Allow javascript files to be compiled. */ 10 | // "checkJs": true, /* Report errors in .js files. */ 11 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 12 | "declaration": true, /* Generates corresponding '.d.ts' file. */ 13 | "sourceMap": true, /* Generates corresponding '.map' file. */ 14 | "outDir": "./dist", /* Redirect output structure to the directory. */ 15 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 16 | // "removeComments": true, /* Do not emit comments to output. */ 17 | // "noEmit": true, /* Do not emit outputs. */ 18 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 19 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 20 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 21 | /* Strict Type-Checking Options */ 22 | "strict": true /* Enable all strict type-checking options. */ 23 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 24 | // "strictNullChecks": true, /* Enable strict null checks. */ 25 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 26 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 27 | /* Additional Checks */ 28 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 29 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 30 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 31 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 32 | /* Module Resolution Options */ 33 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 34 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 35 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 36 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 37 | // "typeRoots": [], /* List of folders to include type definitions from. */ 38 | // "types": [], /* Type declaration files to be included in compilation. */ 39 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 40 | /* Source Map Options */ 41 | // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 42 | // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ 43 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 44 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 45 | /* Experimental Options */ 46 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 47 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "defaultSeverity": "error", 3 | "extends": [ 4 | "tslint:recommended" 5 | ], 6 | "jsRules": {}, 7 | "rules": { 8 | "quotemark": [ 9 | "double" 10 | ], 11 | "interface-name": [ 12 | "never-prefix" 13 | ], 14 | "switch-default": false 15 | }, 16 | "rulesDirectory": [] 17 | } 18 | --------------------------------------------------------------------------------