From ee6302c71c5b1543e729263796b17269876b3887 Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Wed, 14 Aug 2024 21:04:30 +0000 Subject: [PATCH 1/2] Replace websso directory search with directory search basic API --- node/src/handlers/get-auth-callback.js | 41 +++++++++---------- .../integration/get-auth-callback.test.js | 8 ++-- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/node/src/handlers/get-auth-callback.js b/node/src/handlers/get-auth-callback.js index 87370f2..7f1a0a7 100644 --- a/node/src/handlers/get-auth-callback.js +++ b/node/src/handlers/get-auth-callback.js @@ -34,16 +34,18 @@ exports.handler = wrap(async (event) => { return { statusCode: 400 }; }); +async function invokeNuApi(path, headers) { + const url = new URL(process.env.NUSSO_BASE_URL); + url.pathname = path; + return await axios.get(url.toString(), { + headers: { apikey: process.env.NUSSO_API_KEY, ...headers }, + }); +} + async function getNetIdFromToken(nusso) { - const response = await axios.get( - `${process.env.NUSSO_BASE_URL}validateWebSSOToken`, - { - headers: { - apikey: process.env.NUSSO_API_KEY, - webssotoken: nusso, - }, - } - ); + const response = await invokeNuApi("/agentless-websso/validateWebSSOToken", { + webssotoken: nusso, + }); return response?.data?.netid; } @@ -52,14 +54,8 @@ async function redeemSsoToken(event) { const netid = await getNetIdFromToken(nusso); if (netid) { try { - const response = await axios.get( - `${process.env.NUSSO_BASE_URL}validate-with-directory-search-response`, - { - headers: { - apikey: process.env.NUSSO_API_KEY, - webssotoken: nusso, - }, - } + const response = await invokeNuApi( + `/directory-search/res/netid/bas/${netid}` ); return fillInBlanks({ ...response.data.results[0], uid: netid }); } catch (err) { @@ -79,10 +75,13 @@ async function redeemSsoToken(event) { } function fillInBlanks(response) { - const { uid } = response; - response.displayName = ifEmpty(response.displayName, [uid]); - response.mail = ifEmpty(response.mail, `${uid}@e.northwestern.edu`); - return response; + const { uid, displayName, givenName, mail } = response; + return { + uid, + givenName, + displayName: ifEmpty(displayName, [uid]), + mail: ifEmpty(mail, `${uid}@e.northwestern.edu`), + }; } function ifEmpty(val, replacement) { diff --git a/node/test/integration/get-auth-callback.test.js b/node/test/integration/get-auth-callback.test.js index 9263911..a1b9475 100644 --- a/node/test/integration/get-auth-callback.test.js +++ b/node/test/integration/get-auth-callback.test.js @@ -20,13 +20,13 @@ describe("auth callback", function () { .render(); nock(process.env.NUSSO_BASE_URL) - .get("/validateWebSSOToken") + .get("/agentless-websso/validateWebSSOToken") .reply(200, { netid: "uid123" }); }); it("redeems the NUSSO token", async () => { nock(process.env.NUSSO_BASE_URL) - .get("/validate-with-directory-search-response") + .get("/directory-search/res/netid/bas/uid123") .reply(200, { results: [ { displayName: ["Some User"], mail: "some.user@example.com" }, @@ -53,7 +53,7 @@ describe("auth callback", function () { it("fills in the blanks if the directory search result is incomplete", async () => { nock(process.env.NUSSO_BASE_URL) - .get("/validate-with-directory-search-response") + .get("/directory-search/res/netid/bas/uid123") .reply(200, { results: [{ displayName: [], mail: "" }], }); @@ -82,7 +82,7 @@ describe("auth callback", function () { it("assembles a user object from the netID if directory search fails", async () => { nock(process.env.NUSSO_BASE_URL) - .get("/validate-with-directory-search-response") + .get("/directory-search/res/netid/bas/uid123") .reply(500, { fault: { faultstring: From fab7b97c3296ff650f2a523ca3f27c65315d475f Mon Sep 17 00:00:00 2001 From: "Michael B. Klein" Date: Thu, 15 Aug 2024 19:46:21 +0000 Subject: [PATCH 2/2] Update hybrid query fields and operator --- chat/src/helpers/hybrid_query.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chat/src/helpers/hybrid_query.py b/chat/src/helpers/hybrid_query.py index 5a7119d..8e202d5 100644 --- a/chat/src/helpers/hybrid_query.py +++ b/chat/src/helpers/hybrid_query.py @@ -19,8 +19,8 @@ def hybrid_query(query: str, model_id: str, vector_field: str = "embedding", k: "queries": [ filter({ "query_string": { - "default_operator": "AND", - "fields": ["title^5", "all_controlled_labels", "all_ids^5"], + "default_operator": "OR", + "fields": ["title^1", "collection.title^5", "all_controlled_labels", "all_ids^1"], "query": query } }),