Skip to content

Commit

Permalink
Merge pull request #258 from nulib/deploy/staging
Browse files Browse the repository at this point in the history
Deploy API token update (with affiliation) to prod
  • Loading branch information
mbklein committed Aug 29, 2024
2 parents 8e08b17 + c8e46e9 commit d9e7548
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: "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

0 comments on commit d9e7548

Please sign in to comment.