Skip to content

Commit

Permalink
Replace websso directory search with directory search basic API
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Aug 14, 2024
1 parent bf1cfd0 commit ee6302c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
41 changes: 20 additions & 21 deletions node/src/handlers/get-auth-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions node/test/integration/get-auth-callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]" },
Expand All @@ -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: "" }],
});
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ee6302c

Please sign in to comment.