Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"@adobe/spacecat-shared-brand-client": "1.1.35",
"@adobe/spacecat-shared-data-access": "2.104.0",
"@adobe/spacecat-shared-gpt-client": "1.6.16",
"@adobe/spacecat-shared-http-utils": "1.20.0",
"@adobe/spacecat-shared-http-utils": "https://gist.github.com/ravverma/73fbd39cad0536f360791528e21c3857/raw/d90ba46561b05c04c5ee1632e0ba432e0437bd53/adobe-spacecat-shared-http-utils-1.20.0.tgz",
"@adobe/spacecat-shared-ims-client": "1.11.9",
"@adobe/spacecat-shared-rum-api-client": "2.40.7",
"@adobe/spacecat-shared-scrape-client": "2.5.0",
Expand Down
25 changes: 25 additions & 0 deletions src/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,31 @@ export async function getIMSPromiseToken(context) {
);
}

/**
* Get the access token from the Promise Token in authInfo of context.
* @param {object} context - The context of the request.
* @returns {string} accessToken - The access token.
* @throws {ErrorWithStatusCode} - If the promise token is missing.
*/
export async function getAccessToken(context) {
const imsClient = ImsPromiseClient.createFrom(
context,
ImsPromiseClient.CLIENT_TYPE.CONSUMER,
);

const authInfo = context.attributes?.authInfo;
const promiseToken = authInfo.getPromiseToken();
if (!promiseToken) {
throw new ErrorWithStatusCode('Missing promise token', STATUS_BAD_REQUEST);
}

const accessToken = await imsClient.exchangeToken(
promiseToken,
!!context.env?.AUTOFIX_CRYPT_SECRET && !!context.env?.AUTOFIX_CRYPT_SALT,
);
return accessToken;
}

/**
* Build an S3 prefix for site content files.
* @param {string} type - The type of content (e.g., 'scrapes', 'imports', 'accessibility').
Expand Down