Skip to content

Commit 69c7e8e

Browse files
authored
fix(jwt): allow JWT exp to be bigint (#542)
1 parent 0089a07 commit 69c7e8e

File tree

10 files changed

+17
-11
lines changed

10 files changed

+17
-11
lines changed

packages/graphile-build-pg/src/plugins/PgJWTPlugin.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ export default (function PgJWTPlugin(
7070
"A JSON Web Token defined by [RFC 7519](https://tools.ietf.org/html/rfc7519) which securely represents claims between two parties.",
7171
serialize(value) {
7272
const token = attributes.reduce((memo, attr) => {
73-
memo[attr.name] = value[attr.name];
73+
if (attr.name === "exp") {
74+
memo[attr.name] = value[attr.name]
75+
? parseFloat(value[attr.name])
76+
: undefined;
77+
} else {
78+
memo[attr.name] = value[attr.name];
79+
}
7480
return memo;
7581
}, {});
7682
return signJwt(

packages/postgraphile-core/__tests__/integration/__snapshots__/queries-jwt.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Object {
1818
"a": 1,
1919
"b": "2",
2020
"c": "3",
21-
"exp": 2130969600,
21+
"exp": "2130969600",
2222
"role": "yay",
2323
},
2424
},

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/defaultOptions.test.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,7 @@ type JwtToken {
33393339
a: Int
33403340
b: BigFloat
33413341
c: BigInt
3342-
exp: Int
3342+
exp: BigInt
33433343
role: String
33443344
}
33453345

@@ -13419,7 +13419,7 @@ type JwtToken {
1341913419
a: Int
1342013420
b: BigFloat
1342113421
c: BigInt
13422-
exp: Int
13422+
exp: BigInt
1342313423
role: String
1342413424
}
1342513425

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/function-clash.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3339,7 +3339,7 @@ type JwtToken {
33393339
a: Int
33403340
b: BigFloat
33413341
c: BigInt
3342-
exp: Int
3342+
exp: BigInt
33433343
role: String
33443344
}
33453345

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/indexes.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3728,7 +3728,7 @@ type JwtToken {
37283728
a: Int
37293729
b: BigFloat
37303730
c: BigInt
3731-
exp: Int
3731+
exp: BigInt
37323732
role: String
37333733
}
37343734

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/inflect-core.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3344,7 +3344,7 @@ type JwtToken {
33443344
a: Int
33453345
b: BigFloat
33463346
c: BigInt
3347-
exp: Int
3347+
exp: BigInt
33483348
role: String
33493349
}
33503350

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/rbac.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4666,7 +4666,7 @@ type JwtToken {
46664666
a: Int
46674667
b: BigFloat
46684668
c: BigInt
4669-
exp: Int
4669+
exp: BigInt
46704670
role: String
46714671
}
46724672

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simplePrint.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3322,7 +3322,7 @@ type JsonIdentityMutationPayload {
33223322
33233323
type JwtToken {
33243324
role: String
3325-
exp: Int
3325+
exp: BigInt
33263326
a: Int
33273327
b: BigFloat
33283328
c: BigInt

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/skipNodePlugin.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3067,7 +3067,7 @@ type JwtToken {
30673067
a: Int
30683068
b: BigFloat
30693069
c: BigInt
3070-
exp: Int
3070+
exp: BigInt
30713071
role: String
30723072
}
30733073

packages/postgraphile-core/__tests__/kitchen-sink-schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ create function b.type_function_connection_mutation() returns setof b.types as $
388388

389389
create type b.jwt_token as (
390390
role text,
391-
exp integer,
391+
exp bigint,
392392
a integer,
393393
b numeric,
394394
c bigint

0 commit comments

Comments
 (0)