diff --git a/.changeset/large-walls-reflect.md b/.changeset/large-walls-reflect.md new file mode 100644 index 0000000..34320b2 --- /dev/null +++ b/.changeset/large-walls-reflect.md @@ -0,0 +1,5 @@ +--- +"@labdigital/federated-token": patch +--- + +Fix issues when running with bun by converting KeyObject to uint8 diff --git a/src/gateway.ts b/src/gateway.ts index c623938..2ae38ea 100644 --- a/src/gateway.ts +++ b/src/gateway.ts @@ -71,6 +71,7 @@ export class GatewayAuthPlugin }, }); } else { + console.error(e) throw new GraphQLError("Your token is invalid.", { extensions: { code: "INVALID_TOKEN", diff --git a/src/sign.ts b/src/sign.ts index cfa90d3..1a1419c 100644 --- a/src/sign.ts +++ b/src/sign.ts @@ -1,4 +1,5 @@ import * as jose from "jose"; +import { KeyObject } from "node:crypto"; type TokenSignerOptions = { encryptKeys: KeyManagerInterface; @@ -47,7 +48,8 @@ export class TokenSigner { contentEncryptionAlgorithms: ["A256GCM"], } ); - return JSON.parse(result.plaintext.toString()); + const data = new TextDecoder().decode(result.plaintext.buffer) + return JSON.parse(data) } async signJWT(payload: any, exp: number) { @@ -118,7 +120,7 @@ export class KeyManager implements KeyManagerInterface { if (keys.length === 0) { throw new ConfigurationError("Missing keys"); } - this.keys = keys; + this.keys = keys.map((k) => ({ id: k.id, key: this.convertKey(k.key) })); } // getActiveKey returns a key to sign the JWT. It always returns the first key @@ -143,4 +145,13 @@ export class KeyManager implements KeyManagerInterface { } return key; } + + convertKey( + key: KeyObject | jose.KeyLike | Uint8Array + ): Uint8Array | jose.KeyLike { + if (key instanceof KeyObject) { + return new Uint8Array(key.export()); + } + return key; + } }