fix(api): 🐛 Fix oauth token endpoint returning an ISO-8601 string instead of a unix timestamp

This commit is contained in:
Jesse Wierzbinski 2024-05-12 14:01:37 -10:00
parent ff14e5a5d3
commit 9566387273
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View file

@ -128,14 +128,18 @@ export default (app: Hono) =>
access_token: token.accessToken, access_token: token.accessToken,
token_type: "Bearer", token_type: "Bearer",
expires_in: token.expiresAt expires_in: token.expiresAt
? (new Date(token.expiresAt).getTime() - ? Math.floor(
(new Date(token.expiresAt).getTime() -
Date.now()) / Date.now()) /
1000 1000,
)
: null, : null,
id_token: token.idToken, id_token: token.idToken,
refresh_token: null, refresh_token: null,
scope: token.scope, scope: token.scope,
created_at: new Date(token.createdAt).toISOString(), created_at: Math.floor(
new Date(token.createdAt).getTime() / 1000,
),
}); });
} }
} }

View file

@ -152,7 +152,7 @@ describe("POST /oauth/token/", () => {
access_token: expect.any(String), access_token: expect.any(String),
token_type: "Bearer", token_type: "Bearer",
scope: "read write", scope: "read write",
created_at: expect.any(String), created_at: expect.any(Number),
expires_in: expect.any(Number), expires_in: expect.any(Number),
id_token: null, id_token: null,
refresh_token: null, refresh_token: null,