Skip to content

Commit

Permalink
Removing form-data dependency (no longer working?)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Mulligan committed Nov 1, 2023
1 parent fee5587 commit 9cbfc13
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 97 deletions.
26 changes: 15 additions & 11 deletions dist/adobe-ims-servicetoken.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
*
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 3.0.4
* @version 3.0.5
*/
'use strict';

var FormData = require('form-data');
var node_crypto = require('node:crypto');

const AMPERSAND = "&";
const BASE64 = "base64";
const CLIENT_ID = "client_id";
const CLIENT_SECRET = "client_secret";
const CODE = "code";
const CONTENT_TYPE = "content-type";
const DEFAULT_GRANT_TYPE = "authorization_code";
const DEFAULT_URL = "https://ims-na1.adobelogin.com/ims/token";
const EMPTY = "";
const FORM_URLENCODED = "application/x-www-form-urlencoded";
const GRANT_TYPE = "grant_type";
const JWT_TOKEN = "jwt_token";
const POST = "POST";
Expand All @@ -37,29 +39,31 @@ async function token ({
let result;

if (tokens.has(key) === false) {
const form = new FormData();
const body = [
`${CLIENT_ID}=${client_id}`,
`${CLIENT_SECRET}=${client_secret}`
];
let res;

if (grant_type.length > 0) {
form.append(GRANT_TYPE, grant_type);
body.push(`${GRANT_TYPE}=${grant_type}`);
}

form.append(CLIENT_ID, client_id);
form.append(CLIENT_SECRET, client_secret);

if (code.length > 0) {
form.append(CODE, code);
body.push(`${CODE}=${code}`);
}

if (jwt_token.length > 0) {
form.append(JWT_TOKEN, jwt_token);
body.push(`${JWT_TOKEN}=${jwt_token}`);
}

try {
res = await fetch(url, {
method: POST,
headers: form.getHeaders(),
body: form
headers: {
[CONTENT_TYPE]: FORM_URLENCODED
},
body: body.join(AMPERSAND)
});
} catch (err) {
res = {
Expand Down
27 changes: 16 additions & 11 deletions dist/adobe-ims-servicetoken.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
*
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 3.0.4
* @version 3.0.5
*/
import FormData from'form-data';import {createHash}from'node:crypto';const BASE64 = "base64";
import {createHash}from'node:crypto';const AMPERSAND = "&";
const BASE64 = "base64";
const CLIENT_ID = "client_id";
const CLIENT_SECRET = "client_secret";
const CODE = "code";
const CONTENT_TYPE = "content-type";
const DEFAULT_GRANT_TYPE = "authorization_code";
const DEFAULT_URL = "https://ims-na1.adobelogin.com/ims/token";
const EMPTY = "";
const FORM_URLENCODED = "application/x-www-form-urlencoded";
const GRANT_TYPE = "grant_type";
const JWT_TOKEN = "jwt_token";
const POST = "POST";
Expand All @@ -30,29 +33,31 @@ async function token ({
let result;

if (tokens.has(key) === false) {
const form = new FormData();
const body = [
`${CLIENT_ID}=${client_id}`,
`${CLIENT_SECRET}=${client_secret}`
];
let res;

if (grant_type.length > 0) {
form.append(GRANT_TYPE, grant_type);
body.push(`${GRANT_TYPE}=${grant_type}`);
}

form.append(CLIENT_ID, client_id);
form.append(CLIENT_SECRET, client_secret);

if (code.length > 0) {
form.append(CODE, code);
body.push(`${CODE}=${code}`);
}

if (jwt_token.length > 0) {
form.append(JWT_TOKEN, jwt_token);
body.push(`${JWT_TOKEN}=${jwt_token}`);
}

try {
res = await fetch(url, {
method: POST,
headers: form.getHeaders(),
body: form
headers: {
[CONTENT_TYPE]: FORM_URLENCODED
},
body: body.join(AMPERSAND)
});
} catch (err) {
res = {
Expand Down
63 changes: 2 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "adobe-ims-servicetoken",
"version": "3.0.4",
"version": "3.0.5",
"description": "Adobe IMS Service Token lifecycle management",
"source": "src/ims.js",
"main": "dist/adobe-ims-servicetoken.cjs",
Expand Down Expand Up @@ -40,9 +40,6 @@
],
"author": "Jason Mulligan <jason.mulligan@avoidwork.com>",
"license": "BSD-3-Clause",
"dependencies": {
"form-data": "^4.0.0"
},
"devDependencies": {
"@types/node": "^20.8.10",
"auto-changelog": "^2.4.0",
Expand Down
3 changes: 3 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
export const AMPERSAND = "&";
export const BASE64 = "base64";
export const CLIENT_ID = "client_id";
export const CLIENT_SECRET = "client_secret";
export const CODE = "code";
export const CONTENT_TYPE = "content-type";
export const DEFAULT_GRANT_TYPE = "authorization_code";
export const DEFAULT_URL = "https://ims-na1.adobelogin.com/ims/token";
export const EMPTY = "";
export const FORM_URLENCODED = "application/x-www-form-urlencoded";
export const GRANT_TYPE = "grant_type";
export const JWT_TOKEN = "jwt_token";
export const POST = "POST";
Expand Down
24 changes: 14 additions & 10 deletions src/token.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import FormData from "form-data";
import {createHash} from "node:crypto";
import {
AMPERSAND,
BASE64,
CLIENT_ID,
CLIENT_SECRET,
CODE,
CONTENT_TYPE,
DEFAULT_GRANT_TYPE,
DEFAULT_URL,
EMPTY,
FORM_URLENCODED,
GRANT_TYPE,
JWT_TOKEN,
POST,
Expand All @@ -29,29 +31,31 @@ export async function token ({
let result;

if (tokens.has(key) === false) {
const form = new FormData();
const body = [
`${CLIENT_ID}=${client_id}`,
`${CLIENT_SECRET}=${client_secret}`
];
let res;

if (grant_type.length > 0) {
form.append(GRANT_TYPE, grant_type);
body.push(`${GRANT_TYPE}=${grant_type}`);
}

form.append(CLIENT_ID, client_id);
form.append(CLIENT_SECRET, client_secret);

if (code.length > 0) {
form.append(CODE, code);
body.push(`${CODE}=${code}`);
}

if (jwt_token.length > 0) {
form.append(JWT_TOKEN, jwt_token);
body.push(`${JWT_TOKEN}=${jwt_token}`);
}

try {
res = await fetch(url, {
method: POST,
headers: form.getHeaders(),
body: form
headers: {
[CONTENT_TYPE]: FORM_URLENCODED
},
body: body.join(AMPERSAND)
});
} catch (err) {
res = {
Expand Down

0 comments on commit 9cbfc13

Please sign in to comment.