From 7b4f1ed0b9b82bd965f29509f5a03b05a8e50d78 Mon Sep 17 00:00:00 2001 From: Nataliya Issayeva Date: Wed, 27 Oct 2021 16:49:56 -0400 Subject: [PATCH] Add TODOs Signed-off-by: Nataliya Issayeva --- packages/backend-common/src/identity/IdentityClient.ts | 3 +++ .../backend-common/src/tokens/AuthIdentityTokenManager.ts | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/backend-common/src/identity/IdentityClient.ts b/packages/backend-common/src/identity/IdentityClient.ts index b3169b02b3..c69ff1be64 100644 --- a/packages/backend-common/src/identity/IdentityClient.ts +++ b/packages/backend-common/src/identity/IdentityClient.ts @@ -27,6 +27,8 @@ const CLOCK_MARGIN_S = 10; * * @experimental This is not a stable API yet */ + +// TODO: (b2b-auth) integrate IdentityClient into the TokenManager instead export class IdentityClient { private readonly discovery: PluginEndpointDiscovery; private readonly issuer: string; @@ -90,6 +92,7 @@ export class IdentityClient { * Returns the public signing key matching the given jwt token, * or null if no matching key was found */ + // TODO (b2b-auth): switch on type to identify server tokens? private async getKey(rawJwtToken: string): Promise { const { header, payload } = JWT.decode(rawJwtToken, { complete: true, diff --git a/packages/backend-common/src/tokens/AuthIdentityTokenManager.ts b/packages/backend-common/src/tokens/AuthIdentityTokenManager.ts index 2c71ba4d10..c33c4ecd78 100644 --- a/packages/backend-common/src/tokens/AuthIdentityTokenManager.ts +++ b/packages/backend-common/src/tokens/AuthIdentityTokenManager.ts @@ -19,6 +19,7 @@ import { IdentityClient } from '../identity'; import { PluginEndpointDiscovery } from '../discovery'; export class AuthIdentityTokenManager implements TokenManager { + // TODO: (b2b-auth) replace this in favor of actual server token in config likely private readonly SERVER_TOKEN = 'server-token'; private identityClient: IdentityClient; @@ -33,13 +34,15 @@ export class AuthIdentityTokenManager implements TokenManager { return { token: this.SERVER_TOKEN }; } + // TODO: (b2b-auth) authenticate returns a Backstage Identity + // need to figure out what to return after validating a server token async validateToken(token: string): Promise { if (token !== this.SERVER_TOKEN) { try { await this.identityClient.authenticate(token); return; - } catch (e) { - throw new Error('Invalid token'); + } catch (error) { + throw new Error(`Invalid token, ${error}`); } } }