diff --git a/node/src/api/api-token.js b/node/src/api/api-token.js index 13f3e1c0..51a6f490 100644 --- a/node/src/api/api-token.js +++ b/node/src/api/api-token.js @@ -34,6 +34,7 @@ class ApiToken { name: user?.displayName?.[0], email: user?.mail, isLoggedIn: !!user, + primaryAffiliation: user?.primaryAffiliation, }; return this.update(); diff --git a/node/src/handlers/get-auth-callback.js b/node/src/handlers/get-auth-callback.js index 7f1a0a76..abe5232f 100644 --- a/node/src/handlers/get-auth-callback.js +++ b/node/src/handlers/get-auth-callback.js @@ -75,12 +75,14 @@ async function redeemSsoToken(event) { } function fillInBlanks(response) { - const { uid, displayName, givenName, mail } = response; + const { uid, displayName, eduPersonPrimaryAffiliation, givenName, mail } = + response; return { uid, givenName, displayName: ifEmpty(displayName, [uid]), mail: ifEmpty(mail, `${uid}@e.northwestern.edu`), + primaryAffiliation: eduPersonPrimaryAffiliation, }; } diff --git a/node/test/integration/get-auth-callback.test.js b/node/test/integration/get-auth-callback.test.js index a1b94751..3074495e 100644 --- a/node/test/integration/get-auth-callback.test.js +++ b/node/test/integration/get-auth-callback.test.js @@ -29,7 +29,11 @@ describe("auth callback", function () { .get("/directory-search/res/netid/bas/uid123") .reply(200, { results: [ - { displayName: ["Some User"], mail: "some.user@example.com" }, + { + displayName: ["Some User"], + mail: "some.user@example.com", + eduPersonPrimaryAffiliation: "staff", + }, ], }); @@ -48,6 +52,7 @@ describe("auth callback", function () { expect(apiToken.token.sub).to.eq("uid123"); expect(apiToken.token.name).to.eq("Some User"); expect(apiToken.token.email).to.eq("some.user@example.com"); + expect(apiToken.token.primaryAffiliation).to.eq("staff"); expect(apiToken.isLoggedIn()).to.be.true; }); @@ -77,6 +82,7 @@ describe("auth callback", function () { expect(apiToken.token.sub).to.eq("uid123"); expect(apiToken.token.name).to.eq("uid123"); expect(apiToken.token.email).to.eq("uid123@e.northwestern.edu"); + expect(apiToken.token.primaryAffiliation).to.be.undefined; expect(apiToken.isLoggedIn()).to.be.true; });