From 454b032ba545cdadf94ee6772c43ab8c3dd10f3a Mon Sep 17 00:00:00 2001 From: Vladislav Tupikin Date: Wed, 11 Oct 2023 19:33:57 +0300 Subject: [PATCH] JWT and OAuth auths removed (#284) * JWT and OAuth auths removed * XOR3 added * unit tests fixed * build fixed --- README.md | 37 --- package-lock.json | 237 +++++------------- package.json | 8 +- src/clients/baseClient.ts | 6 +- src/config.ts | 18 +- .../authenticationService.ts | 15 -- .../createJWTAuthentication.ts | 27 -- .../createOAuthAuthenticationToken.ts | 27 -- .../authentications/index.ts | 2 - src/utilityTypes.ts | 3 + src/version2/avatars.ts | 5 +- src/version3/avatars.ts | 5 +- .../services/authenticationService.test.ts | 50 ---- 13 files changed, 71 insertions(+), 369 deletions(-) delete mode 100644 src/services/authenticationService/authentications/createJWTAuthentication.ts delete mode 100644 src/services/authenticationService/authentications/createOAuthAuthenticationToken.ts diff --git a/README.md b/README.md index 8415f8f530..f4e609e82a 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,7 @@ Usability, consistency, and performance are key focuses of jira.js, and it also - [Usage](#usage) - [Authentication](#authentication) - [Basic](#basic-authentication) - - [OAuth](#oauth) - [OAuth 2.0](#oauth-20) - - [JWT](#jwt) - [Personal access token](#personal-access-token) - [Example and using algorithm](#example-and-using-algorithm) - [Decreasing Webpack bundle size](#decreasing-webpack-bundle-size) @@ -144,24 +142,6 @@ const client = new Version3Client({ }); ``` -##### [OAuth](https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-oauth-authentication/) - -```typescript -import { Version3Client } from 'jira.js'; - -const client = new Version3Client({ - host: 'https://your-domain.atlassian.net', - authentication: { - oauth: { - consumerKey: 'your consumer key', - consumerSecret: '-----BEGIN RSA PRIVATE KEY-----\n" + "some private key\n" + "-----END RSA PRIVATE KEY-----', - accessToken: 'your access token', - tokenSecret: 'your token secret', - }, - }, -}); -``` - ##### [OAuth 2.0](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/) Only the authorization token is currently supported. To release it, you need to read the [documentation](https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/) and write your own code to get the token. @@ -181,23 +161,6 @@ const client = new Version3Client({ }); ``` -##### [JWT](https://developer.atlassian.com/cloud/jira/platform/understanding-jwt-for-connect-apps/) - -```typescript -import { Version3Client } from 'jira.js'; - -const client = new Version3Client({ - host: 'https://your-domain.atlassian.net', - authentication: { - jwt: { - issuer: 'ISSUER', - secret: 'shhhh', - expiryTimeSeconds: 180, - }, - }, -}); -``` - ##### [Personal access token](https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html) ```typescript diff --git a/package-lock.json b/package-lock.json index 80bbb703c6..13cb39d1e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,21 +9,17 @@ "version": "2.20.1", "license": "MIT", "dependencies": { - "atlassian-jwt": "^2.0.2", "axios": "^1.5.1", "form-data": "^4.0.0", - "oauth": "^0.10.0", "tslib": "^2.6.2" }, "devDependencies": { "@swc-node/register": "^1.6.8", "@swc/helpers": "^0.5.3", - "@types/express": "^4.17.18", "@types/node": "^18.18.4", - "@types/oauth": "^0.9.2", "@types/sinon": "^10.0.19", - "@typescript-eslint/eslint-plugin": "^6.7.4", - "@typescript-eslint/parser": "^6.7.4", + "@typescript-eslint/eslint-plugin": "^6.7.5", + "@typescript-eslint/parser": "^6.7.5", "ava": "^5.3.1", "dotenv": "^16.3.1", "eslint": "^8.51.0", @@ -571,25 +567,6 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, - "node_modules/@types/body-parser": { - "version": "1.19.3", - "resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.3.tgz", - "integrity": "sha512-oyl4jvAfTGX9Bt6Or4H9ni1Z447/tQuxnZsytsCaExKlmJiU8sFgnIBRzJUpKwB5eWn9HuBYlUlVA74q/yN0eQ==", - "dev": true, - "dependencies": { - "@types/connect": "*", - "@types/node": "*" - } - }, - "node_modules/@types/connect": { - "version": "3.4.36", - "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.36.tgz", - "integrity": "sha512-P63Zd/JUGq+PdrM1lv0Wv5SBYeA2+CORvbrXbngriYY0jzLUWfQMQQxOhjONEz/wlHOAxOdY7CY65rgQdTjq2w==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/debug": { "version": "4.1.9", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.9.tgz", @@ -599,36 +576,6 @@ "@types/ms": "*" } }, - "node_modules/@types/express": { - "version": "4.17.18", - "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.18.tgz", - "integrity": "sha512-Sxv8BSLLgsBYmcnGdGjjEjqET2U+AKAdCRODmMiq02FgjwuV75Ut85DRpvFjyw/Mk0vgUOliGRU0UUmuuZHByQ==", - "dev": true, - "dependencies": { - "@types/body-parser": "*", - "@types/express-serve-static-core": "^4.17.33", - "@types/qs": "*", - "@types/serve-static": "*" - } - }, - "node_modules/@types/express-serve-static-core": { - "version": "4.17.37", - "resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.37.tgz", - "integrity": "sha512-ZohaCYTgGFcOP7u6aJOhY9uIZQgZ2vxC2yWoArY+FeDXlqeH66ZVBjgvg+RLVAS/DWNq4Ap9ZXu1+SUQiiWYMg==", - "dev": true, - "dependencies": { - "@types/node": "*", - "@types/qs": "*", - "@types/range-parser": "*", - "@types/send": "*" - } - }, - "node_modules/@types/http-errors": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.2.tgz", - "integrity": "sha512-lPG6KlZs88gef6aD85z3HNkztpj7w2R7HmR3gygjfXCQmsLloWNARFkMuzKiiY8FGdh1XDpgBdrSf4aKDiA7Kg==", - "dev": true - }, "node_modules/@types/json-schema": { "version": "7.0.13", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", @@ -650,12 +597,6 @@ "@types/unist": "*" } }, - "node_modules/@types/mime": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.3.tgz", - "integrity": "sha512-Ys+/St+2VF4+xuY6+kDIXGxbNRO0mesVg0bbxEfB97Od1Vjpjx9KD1qxs64Gcb3CWPirk9Xe+PT4YiiHQ9T+eg==", - "dev": true - }, "node_modules/@types/ms": { "version": "0.7.32", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.32.tgz", @@ -668,54 +609,12 @@ "integrity": "sha512-t3rNFBgJRugIhackit2mVcLfF6IRc0JE4oeizPQL8Zrm8n2WY/0wOdpOPhdtG0V9Q2TlW/axbF1MJ6z+Yj/kKQ==", "dev": true }, - "node_modules/@types/oauth": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/@types/oauth/-/oauth-0.9.2.tgz", - "integrity": "sha512-Nu3/abQ6yR9VlsCdX3aiGsWFkj6OJvJqDvg/36t8Gwf2mFXdBZXPDN3K+2yfeA6Lo2m1Q12F8Qil9TZ48nWhOQ==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, - "node_modules/@types/qs": { - "version": "6.9.8", - "resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.8.tgz", - "integrity": "sha512-u95svzDlTysU5xecFNTgfFG5RUWu1A9P0VzgpcIiGZA9iraHOdSzcxMxQ55DyeRaGCSxQi7LxXDI4rzq/MYfdg==", - "dev": true - }, - "node_modules/@types/range-parser": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.5.tgz", - "integrity": "sha512-xrO9OoVPqFuYyR/loIHjnbvvyRZREYKLjxV4+dY6v3FQR3stQ9ZxIGkaclF7YhI9hfjpuTbu14hZEy94qKLtOA==", - "dev": true - }, "node_modules/@types/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", "integrity": "sha512-OxepLK9EuNEIPxWNME+C6WwbRAOOI2o2BaQEGzz5Lu2e4Z5eDnEo+/aVEDMIXywoJitJ7xWd641wrGLZdtwRyw==", "dev": true }, - "node_modules/@types/send": { - "version": "0.17.2", - "resolved": "https://registry.npmjs.org/@types/send/-/send-0.17.2.tgz", - "integrity": "sha512-aAG6yRf6r0wQ29bkS+x97BIs64ZLxeE/ARwyS6wrldMm3C1MdKwCcnnEwMC1slI8wuxJOpiUH9MioC0A0i+GJw==", - "dev": true, - "dependencies": { - "@types/mime": "^1", - "@types/node": "*" - } - }, - "node_modules/@types/serve-static": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.15.3.tgz", - "integrity": "sha512-yVRvFsEMrv7s0lGhzrggJjNOSmZCdgCjw9xWrPr/kNNLp6FaDfMC1KaYl3TSJ0c58bECwNBMoQrZJ8hA8E1eFg==", - "dev": true, - "dependencies": { - "@types/http-errors": "*", - "@types/mime": "*", - "@types/node": "*" - } - }, "node_modules/@types/sinon": { "version": "10.0.19", "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-10.0.19.tgz", @@ -738,16 +637,16 @@ "dev": true }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.4.tgz", - "integrity": "sha512-DAbgDXwtX+pDkAHwiGhqP3zWUGpW49B7eqmgpPtg+BKJXwdct79ut9+ifqOFPJGClGKSHXn2PTBatCnldJRUoA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.7.5.tgz", + "integrity": "sha512-JhtAwTRhOUcP96D0Y6KYnwig/MRQbOoLGXTON2+LlyB/N35SP9j1boai2zzwXb7ypKELXMx3DVk9UTaEq1vHEw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.7.4", - "@typescript-eslint/type-utils": "6.7.4", - "@typescript-eslint/utils": "6.7.4", - "@typescript-eslint/visitor-keys": "6.7.4", + "@typescript-eslint/scope-manager": "6.7.5", + "@typescript-eslint/type-utils": "6.7.5", + "@typescript-eslint/utils": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -773,15 +672,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.4.tgz", - "integrity": "sha512-I5zVZFY+cw4IMZUeNCU7Sh2PO5O57F7Lr0uyhgCJmhN/BuTlnc55KxPonR4+EM3GBdfiCyGZye6DgMjtubQkmA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.7.5.tgz", + "integrity": "sha512-bIZVSGx2UME/lmhLcjdVc7ePBwn7CLqKarUBL4me1C5feOd663liTGjMBGVcGr+BhnSLeP4SgwdvNnnkbIdkCw==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.7.4", - "@typescript-eslint/types": "6.7.4", - "@typescript-eslint/typescript-estree": "6.7.4", - "@typescript-eslint/visitor-keys": "6.7.4", + "@typescript-eslint/scope-manager": "6.7.5", + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/typescript-estree": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5", "debug": "^4.3.4" }, "engines": { @@ -801,13 +700,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.4.tgz", - "integrity": "sha512-SdGqSLUPTXAXi7c3Ob7peAGVnmMoGzZ361VswK2Mqf8UOYcODiYvs8rs5ILqEdfvX1lE7wEZbLyELCW+Yrql1A==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.7.5.tgz", + "integrity": "sha512-GAlk3eQIwWOJeb9F7MKQ6Jbah/vx1zETSDw8likab/eFcqkjSD7BI75SDAeC5N2L0MmConMoPvTsmkrg71+B1A==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.4", - "@typescript-eslint/visitor-keys": "6.7.4" + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -818,13 +717,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.4.tgz", - "integrity": "sha512-n+g3zi1QzpcAdHFP9KQF+rEFxMb2KxtnJGID3teA/nxKHOVi3ylKovaqEzGBbVY2pBttU6z85gp0D00ufLzViQ==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.7.5.tgz", + "integrity": "sha512-Gs0qos5wqxnQrvpYv+pf3XfcRXW6jiAn9zE/K+DlmYf6FcpxeNYN0AIETaPR7rHO4K2UY+D0CIbDP9Ut0U4m1g==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.7.4", - "@typescript-eslint/utils": "6.7.4", + "@typescript-eslint/typescript-estree": "6.7.5", + "@typescript-eslint/utils": "6.7.5", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -845,9 +744,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.4.tgz", - "integrity": "sha512-o9XWK2FLW6eSS/0r/tgjAGsYasLAnOWg7hvZ/dGYSSNjCh+49k5ocPN8OmG5aZcSJ8pclSOyVKP2x03Sj+RrCA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.7.5.tgz", + "integrity": "sha512-WboQBlOXtdj1tDFPyIthpKrUb+kZf2VroLZhxKa/VlwLlLyqv/PwUNgL30BlTVZV1Wu4Asu2mMYPqarSO4L5ZQ==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -858,13 +757,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.4.tgz", - "integrity": "sha512-ty8b5qHKatlNYd9vmpHooQz3Vki3gG+3PchmtsA4TgrZBKWHNjWfkQid7K7xQogBqqc7/BhGazxMD5vr6Ha+iQ==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.7.5.tgz", + "integrity": "sha512-NhJiJ4KdtwBIxrKl0BqG1Ur+uw7FiOnOThcYx9DpOGJ/Abc9z2xNzLeirCG02Ig3vkvrc2qFLmYSSsaITbKjlg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.4", - "@typescript-eslint/visitor-keys": "6.7.4", + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/visitor-keys": "6.7.5", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -885,17 +784,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.4.tgz", - "integrity": "sha512-PRQAs+HUn85Qdk+khAxsVV+oULy3VkbH3hQ8hxLRJXWBEd7iI+GbQxH5SEUSH7kbEoTp6oT1bOwyga24ELALTA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.7.5.tgz", + "integrity": "sha512-pfRRrH20thJbzPPlPc4j0UNGvH1PjPlhlCMq4Yx7EGjV7lvEeGX0U6MJYe8+SyFutWgSHsdbJ3BXzZccYggezA==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.7.4", - "@typescript-eslint/types": "6.7.4", - "@typescript-eslint/typescript-estree": "6.7.4", + "@typescript-eslint/scope-manager": "6.7.5", + "@typescript-eslint/types": "6.7.5", + "@typescript-eslint/typescript-estree": "6.7.5", "semver": "^7.5.4" }, "engines": { @@ -910,12 +809,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.7.4", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.4.tgz", - "integrity": "sha512-pOW37DUhlTZbvph50x5zZCkFn3xzwkGtNoJHzIM3svpiSkJzwOYr/kVBaXmf+RAQiUDs1AHEZVNPg6UJCJpwRA==", + "version": "6.7.5", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.7.5.tgz", + "integrity": "sha512-3MaWdDZtLlsexZzDSdQWsFQ9l9nL8B80Z4fImSpyllFC/KLqWQRdEcB+gGGO+N3Q2uL40EsG66wZLsohPxNXvg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.7.4", + "@typescript-eslint/types": "6.7.5", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -1236,18 +1135,6 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, - "node_modules/atlassian-jwt": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/atlassian-jwt/-/atlassian-jwt-2.0.2.tgz", - "integrity": "sha512-HgG2p+gJeEqKREnPynEDy76UoShF01jTYMSe0NlRL2rEqXBNDzJiiCyUP7P2cbxcRmI4OC8g40zJjqftFNJ/4A==", - "dependencies": { - "jsuri": "^1.3.1", - "lodash": "^4.17.21" - }, - "engines": { - "node": ">= 0.4.0" - } - }, "node_modules/ava": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ava/-/ava-5.3.1.tgz", @@ -2494,13 +2381,13 @@ } }, "node_modules/eslint-plugin-react/node_modules/resolve": { - "version": "2.0.0-next.4", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-2.0.0-next.4.tgz", - "integrity": "sha512-iMDbmAWtfU+MHpxt/I5iWI7cY6YVEZUQ3MBgPQ++XD1PELuJHIl82xBmObyP2KyQmkNB2dsqF7seoQQiAn5yDQ==", + "version": "2.0.0-next.5", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-2.0.0-next.5.tgz", + "integrity": "sha512-U7WjGVG9sH8tvjW5SmGbQuui75FiyjAX72HX15DwBBwF9dNiQZRQAg9nnPhYy+TUnE0+VcrttuvNI8oSxZcocA==", "dev": true, "peer": true, "dependencies": { - "is-core-module": "^2.9.0", + "is-core-module": "^2.13.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, @@ -3714,14 +3601,6 @@ "integrity": "sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==", "dev": true }, - "node_modules/jsuri": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/jsuri/-/jsuri-1.3.1.tgz", - "integrity": "sha512-LLdAeqOf88/X0hylAI7oSir6QUsz/8kOW0FcJzzu/SJRfORA/oPHycAOthkNp7eLPlTAbqVDFbqNRHkRVzEA3g==", - "engines": { - "node": "*" - } - }, "node_modules/jsx-ast-utils": { "version": "3.3.5", "resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz", @@ -3813,7 +3692,8 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, "node_modules/lodash.get": { "version": "4.4.2", @@ -4548,11 +4428,6 @@ "node": ">=0.10.0" } }, - "node_modules/oauth": { - "version": "0.10.0", - "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.10.0.tgz", - "integrity": "sha512-1orQ9MT1vHFGQxhuy7E/0gECD3fd2fCC+PIX+/jgmU/gI3EpRocXtmtvxCO5x3WZ443FLTLFWNDjl5MPJf9u+Q==" - }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -5180,9 +5055,9 @@ } }, "node_modules/resolve": { - "version": "1.22.6", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.6.tgz", - "integrity": "sha512-njhxM7mV12JfufShqGy3Rz8j11RPdLy4xi15UurGJeoHLfJpVXKdh3ueuOqbYUcDZnffr6X739JBo5LzyahEsw==", + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", "dev": true, "dependencies": { "is-core-module": "^2.13.0", @@ -5393,9 +5268,9 @@ } }, "node_modules/shiki": { - "version": "0.14.4", - "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.14.4.tgz", - "integrity": "sha512-IXCRip2IQzKwxArNNq1S+On4KPML3Yyn8Zzs/xRgcgOWIr8ntIK3IKzjFPfjy/7kt9ZMjc+FItfqHRBg8b6tNQ==", + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/shiki/-/shiki-0.14.5.tgz", + "integrity": "sha512-1gCAYOcmCFONmErGTrS1fjzJLA7MGZmKzrBNX7apqSwhyITJg2O102uFzXUeBxNnEkDA9vHIKLyeKq0V083vIw==", "dev": true, "dependencies": { "ansi-sequence-parser": "^1.1.0", diff --git a/package.json b/package.json index a3f762728f..bd1c5ceb68 100644 --- a/package.json +++ b/package.json @@ -64,12 +64,10 @@ "devDependencies": { "@swc-node/register": "^1.6.8", "@swc/helpers": "^0.5.3", - "@types/express": "^4.17.18", "@types/node": "^18.18.4", - "@types/oauth": "^0.9.2", "@types/sinon": "^10.0.19", - "@typescript-eslint/eslint-plugin": "^6.7.4", - "@typescript-eslint/parser": "^6.7.4", + "@typescript-eslint/eslint-plugin": "^6.7.5", + "@typescript-eslint/parser": "^6.7.5", "ava": "^5.3.1", "dotenv": "^16.3.1", "eslint": "^8.51.0", @@ -86,10 +84,8 @@ "typescript": "^5.2.2" }, "dependencies": { - "atlassian-jwt": "^2.0.2", "axios": "^1.5.1", "form-data": "^4.0.0", - "oauth": "^0.10.0", "tslib": "^2.6.2" } } diff --git a/src/clients/baseClient.ts b/src/clients/baseClient.ts index 70eb8a8043..5fdc081d0b 100644 --- a/src/clients/baseClient.ts +++ b/src/clients/baseClient.ts @@ -98,11 +98,7 @@ export class BaseClient implements Client { const modifiedRequestConfig = { ...requestConfig, headers: this.removeUndefinedProperties({ - Authorization: await AuthenticationService.getAuthenticationToken(this.config.authentication, { - baseURL: this.config.host, - url: this.instance.getUri(requestConfig), - method: requestConfig.method!, - }), + Authorization: await AuthenticationService.getAuthenticationToken(this.config.authentication), ...requestConfig.headers, }), }; diff --git a/src/config.ts b/src/config.ts index 22c2817e6a..17f645361c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -10,8 +10,6 @@ export interface Config { baseRequestConfig?: Config.BaseRequestConfig; authentication?: Config.Authentication; middlewares?: Config.Middlewares; - /** @deprecated Disabled. Will be removed in the next major version */ - telemetry?: Config.Telemetry; /** Enable new API error handling. `false` by default. */ newErrorHandling?: boolean; } @@ -19,31 +17,17 @@ export interface Config { export namespace Config { export type BaseRequestConfig = RequestConfig; export type Error = AxiosError; - /** @deprecated Disabled. Will be removed in the next major version */ - export type Telemetry = boolean | any; - export type Authentication = UtilityTypes.XOR< - { - jwt: Authentication.JWT; - }, - UtilityTypes.XOR< - { - oauth: Authentication.OAuth; - }, - UtilityTypes.XOR< + export type Authentication = UtilityTypes.XOR3< { personalAccessToken: Authentication.PersonalAccessToken; }, - UtilityTypes.XOR< { basic: Authentication.Basic; }, { oauth2: Authentication.OAuth2; } - > - > - > >; export interface Middlewares { diff --git a/src/services/authenticationService/authenticationService.ts b/src/services/authenticationService/authenticationService.ts index e238d0177e..8d03771dcc 100644 --- a/src/services/authenticationService/authenticationService.ts +++ b/src/services/authenticationService/authenticationService.ts @@ -1,20 +1,13 @@ import { Config } from '../../config'; import { createBasicAuthenticationToken, - createJWTAuthentication, createOAuth2AuthenticationToken, - createOAuthAuthenticationToken, createPATAuthentication, } from './authentications'; export namespace AuthenticationService { export async function getAuthenticationToken( authentication: Config.Authentication | undefined, - requestData?: { - baseURL: string; - url: string; - method: string; - }, ): Promise { if (!authentication) { return undefined; @@ -24,18 +17,10 @@ export namespace AuthenticationService { return createBasicAuthenticationToken(authentication.basic); } - if (authentication.oauth) { - return createOAuthAuthenticationToken(authentication.oauth, requestData!); - } - if (authentication.oauth2) { return createOAuth2AuthenticationToken(authentication.oauth2); } - if (authentication.jwt) { - return createJWTAuthentication(authentication.jwt, requestData!); - } - if (authentication.personalAccessToken) { return createPATAuthentication(authentication.personalAccessToken); } diff --git a/src/services/authenticationService/authentications/createJWTAuthentication.ts b/src/services/authenticationService/authentications/createJWTAuthentication.ts deleted file mode 100644 index 43f0fa83ed..0000000000 --- a/src/services/authenticationService/authentications/createJWTAuthentication.ts +++ /dev/null @@ -1,27 +0,0 @@ -import * as jwt from 'atlassian-jwt'; -import { Config } from '../../../config'; - -export function createJWTAuthentication( - authenticationData: Config.Authentication.JWT, - requestData: { - method: string; - url: string; - }, -) { - const { method, url } = requestData; - - const now = Math.floor(Date.now() / 1000); - const expire = now + (authenticationData.expiryTimeSeconds ?? 180); - - const request = jwt.fromMethodAndUrl(method, url); - const tokenData = { - iss: authenticationData.issuer, - qsh: jwt.createQueryStringHash(request), - iat: now, - exp: expire, - }; - - const token = jwt.encodeSymmetric(tokenData, authenticationData.secret); - - return `JWT ${token}`; -} diff --git a/src/services/authenticationService/authentications/createOAuthAuthenticationToken.ts b/src/services/authenticationService/authentications/createOAuthAuthenticationToken.ts deleted file mode 100644 index a6d070f478..0000000000 --- a/src/services/authenticationService/authentications/createOAuthAuthenticationToken.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Config } from '../../../config'; -import { OAuth } from 'oauth'; - -export function createOAuthAuthenticationToken( - authenticationData: Config.Authentication.OAuth, - requestData: { baseURL: string; url: string; method: string }, -) { - const { baseURL, url, method } = requestData; - - const oauthUrl = `${baseURL}/plugins/servlet/oauth/`; - const oauth = new OAuth( - `${oauthUrl}request-token`, - `${oauthUrl}access-token`, - authenticationData.consumerKey, - authenticationData.consumerSecret, - '1.0', - null, - 'RSA-SHA1', - ); - - return oauth.authHeader( - new URL(url, baseURL).toString(), - authenticationData.accessToken, - authenticationData.tokenSecret, - method, - ); -} diff --git a/src/services/authenticationService/authentications/index.ts b/src/services/authenticationService/authentications/index.ts index f5dd777111..0ae8863d09 100644 --- a/src/services/authenticationService/authentications/index.ts +++ b/src/services/authenticationService/authentications/index.ts @@ -1,5 +1,3 @@ export * from './createBasicAuthenticationToken'; -export * from './createJWTAuthentication'; export * from './createOAuth2AuthenticationToken'; -export * from './createOAuthAuthenticationToken'; export * from './createPATAuthentication'; diff --git a/src/utilityTypes.ts b/src/utilityTypes.ts index 413c0a5643..55915460e0 100644 --- a/src/utilityTypes.ts +++ b/src/utilityTypes.ts @@ -4,4 +4,7 @@ export namespace UtilityTypes { /** Get the XOR type which could make 2 types exclude each other */ export type XOR = T | U extends object ? (Without & U) | (Without & T) : T | U; + + /** Get the XOR type for 3 types */ + export type XOR3 = XOR, V>; } diff --git a/src/version2/avatars.ts b/src/version2/avatars.ts index 4b0c5f6f30..d705d7a35f 100644 --- a/src/version2/avatars.ts +++ b/src/version2/avatars.ts @@ -235,7 +235,10 @@ export class Avatars { * - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) * for at least one project the issue type is used in. */ - async getAvatarImageByID(parameters: Parameters.GetAvatarImageByID, callback?: never): Promise; + async getAvatarImageByID( + parameters: Parameters.GetAvatarImageByID, + callback?: never, + ): Promise; async getAvatarImageByID( parameters: Parameters.GetAvatarImageByID, callback?: Callback, diff --git a/src/version3/avatars.ts b/src/version3/avatars.ts index f72b006ffd..ef06946733 100644 --- a/src/version3/avatars.ts +++ b/src/version3/avatars.ts @@ -235,7 +235,10 @@ export class Avatars { * - For custom issue type avatars, _Browse projects_ [project permission](https://confluence.atlassian.com/x/yodKLg) * for at least one project the issue type is used in. */ - async getAvatarImageByID(parameters: Parameters.GetAvatarImageByID, callback?: never): Promise; + async getAvatarImageByID( + parameters: Parameters.GetAvatarImageByID, + callback?: never, + ): Promise; async getAvatarImageByID( parameters: Parameters.GetAvatarImageByID, callback?: Callback, diff --git a/tests/unit/services/authenticationService.test.ts b/tests/unit/services/authenticationService.test.ts index 4aa5d92cd1..1dd43cf51f 100644 --- a/tests/unit/services/authenticationService.test.ts +++ b/tests/unit/services/authenticationService.test.ts @@ -1,7 +1,5 @@ -import * as sinon from 'sinon'; import { AuthenticationService } from '../../../src/services/authenticationService'; import { Config } from '../../../src'; -import { OAuth } from 'oauth'; import test from 'ava'; test('should return undefined when authentication does not used', async t => { @@ -38,54 +36,6 @@ test('should return Basic authentication token for apiToken case', async t => { t.is(token, 'Basic dGVzdF9lbWFpbEB0ZXN0LnF3ZTp0ZXN0X2FwaVRva2Vu'); }); -// Valid RSA keypair used to test RSA-SHA1 signature method -const RsaPrivateKey = - '-----BEGIN RSA PRIVATE KEY-----\n' + - 'MIICXQIBAAKBgQDizE4gQP5nPQhzof/Vp2U2DDY3UY/Gxha2CwKW0URe7McxtnmE\n' + - 'CrZnT1n/YtfrrCNxY5KMP4o8hMrxsYEe05+1ZGFT68ztms3puUxilU5E3BQMhz1t\n' + - 'JMJEGcTt8nZUlM4utli7fHgDtWbhvqvYjRMGn3AjyLOfY8XZvnFkGjipvQIDAQAB\n' + - 'AoGAKgk6FcpWHOZ4EY6eL4iGPt1Gkzw/zNTcUsN5qGCDLqDuTq2Gmk2t/zn68VXt\n' + - 'tVXDf/m3qN0CDzOBtghzaTZKLGhnSewQ98obMWgPcvAsb4adEEeW1/xigbMiaW2X\n' + - 'cu6GhZxY16edbuQ40LRrPoVK94nXQpj8p7w4IQ301Sm8PSECQQD1ZlOj4ugvfhEt\n' + - 'exi4WyAaM45fylmN290UXYqZ8SYPI/VliDytIlMfyq5Rv+l+dud1XDPrWOQ0ImgV\n' + - 'HJn7uvoZAkEA7JhHNmHF9dbdF9Koj86K2Cl6c8KUu7U7d2BAuB6pPkt8+D8+y4St\n' + - 'PaCmN4oP4X+sf5rqBYoXywHlqEei2BdpRQJBAMYgR4cZu7wcXGIL8HlnmROObHSK\n' + - 'OqN9z5CRtUV0nPW8YnQG+nYOMG6KhRMbjri750OpnYF100kEPmRNI0VKQIECQE8R\n' + - 'fQsRleTYz768ahTVQ9WF1ySErMwmfx8gDcD6jjkBZVxZVpURXAwyehopi7Eix/VF\n' + - 'QlxjkBwKIEQi3Ks297kCQQCL9by1bueKDMJO2YX1Brm767pkDKkWtGfPS+d3xMtC\n' + - 'KJHHCqrS1V+D5Q89x5wIRHKxE5UMTc0JNa554OxwFORX\n' + - '-----END RSA PRIVATE KEY-----'; - -const RsaPublicKey = - '-----BEGIN PUBLIC KEY-----\n' + - 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDizE4gQP5nPQhzof/Vp2U2DDY3\n' + - 'UY/Gxha2CwKW0URe7McxtnmECrZnT1n/YtfrrCNxY5KMP4o8hMrxsYEe05+1ZGFT\n' + - '68ztms3puUxilU5E3BQMhz1tJMJEGcTt8nZUlM4utli7fHgDtWbhvqvYjRMGn3Aj\n' + - 'yLOfY8XZvnFkGjipvQIDAQAB\n' + - '-----END PUBLIC KEY-----'; - -test('OAuth 1.0 authentication', async t => { - const authentication: Config.Authentication = { - oauth: { - accessToken: 'accessToken', - tokenSecret: 'tokenSecret', - consumerKey: RsaPublicKey, - consumerSecret: RsaPrivateKey, - }, - }; - - const stub = sinon.stub(OAuth.prototype, 'authHeader'); - - await AuthenticationService.getAuthenticationToken(authentication, { - baseURL: 'http://localhost', - method: 'POST', - url: '/rest/agile/1.0/board', - }); - - t.truthy(stub.calledOnce); - stub.restore(); -}); - test('should generate Bearer Header correctly for Personal Access Token', async t => { const authentication: Config.Authentication = { personalAccessToken: 'secretPAT',