Skip to content

Commit

Permalink
Switch back to custom token validation
Browse files Browse the repository at this point in the history
  • Loading branch information
slitviachenko committed May 24, 2024
1 parent d8c3829 commit 0d3c179
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
42 changes: 21 additions & 21 deletions actions/AuthAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,13 @@ const { checkForAdobeInternalUser } = require('./ActionUtils.js');
const logger = Core.Logger('AuthAction');

/**
* Extracts an Adobe IMS organization ID from the 'x-gw-ims-org-id' header
* Extracts an Adobe IMS organization ID from the 'X-Org-Id' header
*
* @param {object} params action input parameters
* @returns {string|undefined} the Adobe IMS organization ID string, or undefined if not present
*/
function getImsOrg(params) {
return (params.__ow_headers && params.__ow_headers['x-gw-ims-org-id']) ? params.__ow_headers['x-gw-ims-org-id'] : undefined;
}

async function getImsProfile(endpoint, clientId, token) {
try {
const response = await wretch(`${endpoint}/ims/profile/v1`)
.addon(QueryStringAddon).query({
client_id: clientId,
})
.headers({
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
})
.get()
.json();
return response;
} catch (error) {
logger.error(error);
return null;
}
return (params.__ow_headers && params.__ow_headers['x-org-id']) ? params.__ow_headers['x-org-id'] : undefined;
}

async function isValidToken(endpoint, clientId, token) {
Expand Down Expand Up @@ -94,6 +75,25 @@ async function getAccessToken(params) {
}
}

async function getImsProfile(endpoint, clientId, token) {
try {
const response = await wretch(`${endpoint}/ims/profile/v1`)
.addon(QueryStringAddon).query({
client_id: clientId,
})
.headers({
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
})
.get()
.json();
return response;
} catch (error) {
logger.error(error);
return null;
}
}

async function checkForProductContext(profile, org, productContext) {
try {
if (Array.isArray(profile.projectedProductContext)) {
Expand Down
4 changes: 2 additions & 2 deletions actions/FirefallClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class FirefallClient {
try {
const response = await wretch(`${this.endpoint}/v1/completions`, { requestTimeout: REQUEST_TIMEOUT })
.headers({
'x-gw-ims-org-id': this.org,
'x-org-id': this.org,
'x-api-key': this.apiKey,
Authorization: `Bearer ${this.accessToken}`,
'Content-Type': 'application/json',
Expand Down Expand Up @@ -88,7 +88,7 @@ class FirefallClient {
.headers({
Authorization: `Bearer ${this.accessToken}`,
'x-api-key': this.apiKey,
'x-gw-ims-org-id': this.org,
'x-org-id': this.org,
'Content-Type': 'application/json',
})
.post({
Expand Down
6 changes: 3 additions & 3 deletions web-src/src/services/AemService.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AemService {
return wretch(this.cfEndpoint)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.post({
command: 'getFragment',
Expand All @@ -53,7 +53,7 @@ export class AemService {
return wretch(this.cfEndpoint)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.post({
command: 'getFragmentModel',
Expand All @@ -68,7 +68,7 @@ export class AemService {
return wretch(this.cfEndpoint)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.post({
command: 'createFragmentVariation',
Expand Down
2 changes: 1 addition & 1 deletion web-src/src/services/CsvParserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CsvParserService {
const json = await wretch(this.csvParserEndpoint)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.addon(QueryStringAddon)
.query({ url })
Expand Down
6 changes: 3 additions & 3 deletions web-src/src/services/FirefallService.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class FirefallService {
const { jobId } = await wretch(this.completeEndpoint)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.post({
prompt,
Expand All @@ -85,7 +85,7 @@ export class FirefallService {
return wretch(`${this.completeEndpoint}?jobId=${jobId}`)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.get()
.json();
Expand All @@ -107,7 +107,7 @@ export class FirefallService {
const { feedback_id } = await wretch(this.feedbackEndpoint)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.post({
queryId,
Expand Down
2 changes: 1 addition & 1 deletion web-src/src/services/TargetService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class TargetService {
return wretch(url)
.auth(`Bearer ${this.accessToken}`)
.headers({
'x-gw-ims-org-id': this.imsOrg,
'x-org-id': this.imsOrg,
})
.accept('application/json')
.get()
Expand Down

0 comments on commit 0d3c179

Please sign in to comment.