From d63cc1fe5267b1d01eb9dffc4ea330f7daafea80 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sun, 27 Dec 2020 09:45:06 +0100 Subject: [PATCH 1/3] fix: token expiration in s, not ms --- plugins/auth-backend/src/identity/TokenFactory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/auth-backend/src/identity/TokenFactory.ts b/plugins/auth-backend/src/identity/TokenFactory.ts index c4c259ed22..36622332e0 100644 --- a/plugins/auth-backend/src/identity/TokenFactory.ts +++ b/plugins/auth-backend/src/identity/TokenFactory.ts @@ -69,7 +69,7 @@ export class TokenFactory implements TokenIssuer { const sub = params.claims.sub; const aud = 'backstage'; const iat = Math.floor(Date.now() / MS_IN_S); - const exp = iat + this.keyDurationSeconds * MS_IN_S; + const exp = iat + this.keyDurationSeconds; this.logger.info(`Issuing token for ${sub}`); From cc046682e2ef1ad5ab9ccd1a834704f64c8d197f Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sun, 27 Dec 2020 09:55:19 +0100 Subject: [PATCH 2/3] Add changeset --- .changeset/warm-pets-sin.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/warm-pets-sin.md diff --git a/.changeset/warm-pets-sin.md b/.changeset/warm-pets-sin.md new file mode 100644 index 0000000000..3a9197e7f2 --- /dev/null +++ b/.changeset/warm-pets-sin.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': patch +--- + +fix bug in token expiration date From 4975224d8ec65bd725cca8a55b67cf48bccabafb Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Sun, 27 Dec 2020 10:52:18 +0100 Subject: [PATCH 3/3] Adjust test --- plugins/auth-backend/src/identity/TokenFactory.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/auth-backend/src/identity/TokenFactory.test.ts b/plugins/auth-backend/src/identity/TokenFactory.test.ts index 4303401ee6..8b719799b1 100644 --- a/plugins/auth-backend/src/identity/TokenFactory.test.ts +++ b/plugins/auth-backend/src/identity/TokenFactory.test.ts @@ -87,7 +87,7 @@ describe('TokenFactory', () => { iat: expect.any(Number), exp: expect.any(Number), }); - expect(payload.exp).toBe(payload.iat + keyDurationSeconds * 1000); + expect(payload.exp).toBe(payload.iat + keyDurationSeconds); }); it('should generate new signing keys when the current one expires', async () => {