Skip to content

Commit d386f82

Browse files
committed
fix(coms): use username field for user search in coms service
- BCSC logins for coms use the entire sub value not just what is before the at symbol. So made switch to `username` as it is now available for searching/indexing users in COMS. - Cleaned up some variable assignments and checks. Signed-off-by: qhanson55 <quinn.hanson@gov.bc.ca>
1 parent 5faae3a commit d386f82

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

app/src/services/coms.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function comsAxios(options: AxiosRequestConfig = {}): AxiosInstance {
3434
const sak = config.get<string>('server.objectStorage.secretAccessKey');
3535
const b64 = Buffer.from(ak + ':' + sak).toString('base64');
3636

37-
if (!options.headers) options.headers = {};
37+
options.headers ??= {};
3838
options.headers.Authorization = `Basic ${b64}`;
3939
options.headers['x-amz-bucket'] = config.get('server.objectStorage.bucket');
4040
options.headers['x-amz-endpoint'] = config.get('server.objectStorage.endpoint');
@@ -92,8 +92,7 @@ export const getObject = async (bearerToken: string, objectId: string) => {
9292
export const searchUser = async (currentContext: CurrentContext) => {
9393
const { status, headers, data } = await comsAxios({
9494
headers: { Authorization: `Bearer ${currentContext.bearerToken}` }
95-
// Update to use username (sub) if COMS ever opens that up
96-
}).get('/user', { params: { identityId: getCurrentSubject(currentContext).split('@')[0].toUpperCase() } });
95+
}).get('/user', { params: { username: getCurrentSubject(currentContext) } });
9796
return { status, headers, data };
9897
};
9998

@@ -120,8 +119,8 @@ export const assignPermissions = async (tx: PrismaTransactionClient, currentCont
120119
try {
121120
const [user, bucket] = await Promise.all([searchUser(currentContext), getBucket()]);
122121

123-
const { userId } = user.data[0];
124-
const { bucketId } = bucket.data;
122+
const userId = user.data?.[0]?.userId;
123+
const bucketId = bucket.data?.bucketId;
125124

126125
if (!userId || !bucketId) {
127126
throw new Error('Unable to obtain userId or bucketId');

0 commit comments

Comments
 (0)