Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass primary user affiliation through in API token/whoami #257

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: "some.user@example.com" },
{
displayName: ["Some User"],
mail: "some.user@example.com",
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("some.user@example.com");
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("uid123@e.northwestern.edu");
expect(apiToken.token.primaryAffiliation).to.be.undefined;
expect(apiToken.isLoggedIn()).to.be.true;
});

Expand Down
Loading