Skip to content

Commit

Permalink
Don't use a async call for getSubject
Browse files Browse the repository at this point in the history
  • Loading branch information
mvantellingen committed Dec 27, 2023
1 parent 491d7ad commit 3df5163
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-spiders-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/federated-token": patch
---

Don't use a async call for getSubject
2 changes: 1 addition & 1 deletion src/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe("PublicFederatedToken", async () => {
test("createAccessJWT with TokenSigner create hook", async () => {
const signer = new TokenSigner({
...signOptions,
getSubject: async (token) => token.tokens.exampleName?.sub,
getSubject: (token) => token.tokens.exampleName?.sub,
});

const token = new PublicFederatedToken();
Expand Down
3 changes: 1 addition & 2 deletions src/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@ export class PublicFederatedToken extends FederatedToken {
async createAccessJWT(signer: TokenSigner) {
const exp = this.getExpireTime();
const fingerprint = generateFingerprint();
const subject = await signer.getSubject(this);

const payload: JWTPayload = {
...this.values,
exp,
sub: subject,
sub: signer.getSubject(this),
jwe: await signer.encryptObject(this.tokens),
_fingerprint: hashFingerprint(fingerprint),
};
Expand Down
4 changes: 2 additions & 2 deletions src/sign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type TokenSignerOptions = {
signKeys: KeyManagerInterface;
audience: string;
issuer: string;
getSubject?: (token: PublicFederatedToken) => Promise<string>;
getSubject?: (token: PublicFederatedToken) => string;
};

export class ConfigurationError extends Error {}
Expand Down Expand Up @@ -54,7 +54,7 @@ export class TokenSigner {
return JSON.parse(data);
}

async getSubject(token: PublicFederatedToken): Promise<string | undefined> {
getSubject(token: PublicFederatedToken): string | undefined {
return this.config.getSubject ? this.config.getSubject(token) : undefined;
}

Expand Down

0 comments on commit 3df5163

Please sign in to comment.