Skip to content

Commit

Permalink
Merge pull request #257 from nulib/5199-add-user-affiliation-to-token
Browse files Browse the repository at this point in the history
Pass primary user affiliation through in API token/whoami
  • Loading branch information
mbklein authored Aug 29, 2024
2 parents 30b9bbc + f00ef56 commit c8e46e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions node/src/api/api-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ApiToken {
name: user?.displayName?.[0],
email: user?.mail,
isLoggedIn: !!user,
primaryAffiliation: user?.primaryAffiliation,
};

return this.update();
Expand Down
4 changes: 3 additions & 1 deletion node/src/handlers/get-auth-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
8 changes: 7 additions & 1 deletion node/test/integration/get-auth-callback.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ describe("auth callback", function () {
.get("/directory-search/res/netid/bas/uid123")
.reply(200, {
results: [
{ displayName: ["Some User"], mail: "[email protected]" },
{
displayName: ["Some User"],
mail: "[email protected]",
eduPersonPrimaryAffiliation: "staff",
},
],
});

Expand All @@ -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("[email protected]");
expect(apiToken.token.primaryAffiliation).to.eq("staff");
expect(apiToken.isLoggedIn()).to.be.true;
});

Expand Down Expand Up @@ -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("[email protected]");
expect(apiToken.token.primaryAffiliation).to.be.undefined;
expect(apiToken.isLoggedIn()).to.be.true;
});

Expand Down

0 comments on commit c8e46e9

Please sign in to comment.