Skip to content

Commit

Permalink
ENG-0000 - Allow Explicit Authentication Header (#361)
Browse files Browse the repository at this point in the history
Suppresses the built-in logic for adding authentication headers if the
requestor provides one of their own.

Also fixes recent changes to aims-client.ts to pass linting.
  • Loading branch information
mcnielsen authored Apr 19, 2024
1 parent de9c10d commit ad70d4a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@al/core",
"version": "1.2.26",
"version": "1.2.27",
"description": "Node Enterprise Packages for Alert Logic (NEPAL) Core Library",
"main": "./dist/index.cjs.js",
"types": "./dist/index.d.ts",
Expand Down
11 changes: 6 additions & 5 deletions src/aims-client/aims-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class AIMSClientInstance implements AlValidationSchemaProvider {
private client:AlApiClient;
private serviceName = 'aims';
private serviceVersion:string = "v1";
/* tslint:disable:variable-name*/
private _usersDict = {};
public get usersDict() {
return this._usersDict;
Expand Down Expand Up @@ -148,23 +149,23 @@ export class AIMSClientInstance implements AlValidationSchemaProvider {
* @param {string[]} userIds - Array of user IDs to load details for.
* @returns {Promise<void>} A promise that resolves once all user details are loaded.
*/
async loadUserNames(userIds: string[]): Promise<void> {
var promises: Promise<AIMSUser>[] = [];
async loadUserNames(userIds: string[]): Promise<void> {
let promises: Promise<AIMSUser>[] = [];
userIds.forEach((id) => {
if (!(id in this._usersDict)) {
promises.push(AIMSClient.getUserDetailsByUserId(id));
}
});
var results = await Promise.allSettled(promises);
let results = await Promise.allSettled(promises);
results.forEach((result, index) => {
var id = userIds[index];
let id = userIds[index];
if (result.status === 'fulfilled') {
this._usersDict[id] = result.value.name ?? '';
} else if(result.status === 'rejected') {
this._usersDict[id] = 'Unknown User';
}
});
}
}

/**
* Get user permissions
Expand Down
6 changes: 4 additions & 2 deletions src/session/al-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,10 +714,12 @@ export class AlSessionInstance
||
( this.authenticatedStacks.includes( event.request.service_stack ) && event.request.aimsAuthHeader !== false ) ) {
event.request.headers = event.request.headers || {};
if ( this.sessionData?.fortraSession ) {
if ( ! ( 'X-AIMS-Auth-Token' in event.request.headers ) && ! ( 'Authorization' in event.request.headers ) ) {
if ( this.sessionData?.fortraSession ) {
event.request.headers['Authorization'] = `Bearer ${this.sessionData.fortraSession.accessToken}`;
} else {
} else {
event.request.headers['X-AIMS-Auth-Token'] = this.getToken();
}
}
}
}
Expand Down

0 comments on commit ad70d4a

Please sign in to comment.