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

Check for values modified in deserializeAccessToken #27

Merged
merged 4 commits into from
Feb 20, 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
9 changes: 9 additions & 0 deletions .changeset/giant-badgers-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@labdigital/federated-token": patch
---

Check for values modified in deserializeAccessToken

When you only set a value in a service, the token did not get updated in the gateway.
This was because the valueModified was only set after a token change, not just a value change.
This changes improves the check to fix that.
4 changes: 4 additions & 0 deletions src/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ describe("FederatedToken", () => {
federatedToken.isAccessTokenModified(),
"isModified should be true when trackModified is true and token is modified"
);
assert.isTrue(
federatedToken.isValueModified(),
"isModified should be true when trackModified is true and value is modified"
);
});

test("serializeAccessToken", () => {
Expand Down
13 changes: 8 additions & 5 deletions src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,15 @@ export class FederatedToken {
Buffer.from(at, "base64").toString("ascii")
);

// Merge tokens into this object. Checking for modified tokens
for (const k in token.tokens) {
if (trackModified && !isEqual(this.tokens[k], token.tokens[k])) {
this._accessTokenModified = true;
}
if (trackModified) {
this._valueModified = !isEqual(this.values, token.values);

this._accessTokenModified = Object.keys(token.tokens).some(
(key) => !isEqual(this.tokens[key], token.tokens[key])
);
}

// Merge tokens and values into "this" object.
this.tokens = {
...this.tokens,
...token.tokens,
Expand Down
Loading