From 24152c0c52a75c3b633cbd5088994126ad57c536 Mon Sep 17 00:00:00 2001 From: kvmw Date: Thu, 3 Nov 2022 11:54:41 +0100 Subject: [PATCH 1/3] Inject optional CatalogApi in auth-backend router Signed-off-by: kvmw --- plugins/auth-backend/src/service/router.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/auth-backend/src/service/router.ts b/plugins/auth-backend/src/service/router.ts index 7240ba1bcb..8013777415 100644 --- a/plugins/auth-backend/src/service/router.ts +++ b/plugins/auth-backend/src/service/router.ts @@ -28,7 +28,7 @@ import { TokenManager, } from '@backstage/backend-common'; import { assertError, NotFoundError } from '@backstage/errors'; -import { CatalogClient } from '@backstage/catalog-client'; +import { CatalogApi, CatalogClient } from '@backstage/catalog-client'; import { Config } from '@backstage/config'; import { createOidcRouter, TokenFactory, KeyStores } from '../identity'; import session from 'express-session'; @@ -48,6 +48,7 @@ export interface RouterOptions { tokenManager: TokenManager; tokenFactoryAlgorithm?: string; providerFactories?: ProviderFactories; + catalogApi?: CatalogApi; } /** @public */ @@ -62,6 +63,7 @@ export async function createRouter( tokenManager, tokenFactoryAlgorithm, providerFactories, + catalogApi, } = options; const router = Router(); @@ -78,7 +80,6 @@ export async function createRouter( logger: logger.child({ component: 'token-factory' }), algorithm: tokenFactoryAlgorithm, }); - const catalogApi = new CatalogClient({ discoveryApi: discovery }); const secret = config.getOptionalString('auth.session.secret'); if (secret) { @@ -127,7 +128,8 @@ export async function createRouter( logger, resolverContext: CatalogAuthResolverContext.create({ logger, - catalogApi, + catalogApi: + catalogApi ?? new CatalogClient({ discoveryApi: discovery }), tokenIssuer, tokenManager, }), From d80833fe0c401896aaa7477706c988b28ae9bb8d Mon Sep 17 00:00:00 2001 From: kvmw Date: Mon, 7 Nov 2022 14:25:07 +0100 Subject: [PATCH 2/3] Add changeset Signed-off-by: kvmw --- .changeset/wicked-pumas-nail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wicked-pumas-nail.md diff --git a/.changeset/wicked-pumas-nail.md b/.changeset/wicked-pumas-nail.md new file mode 100644 index 0000000000..c9e05aff74 --- /dev/null +++ b/.changeset/wicked-pumas-nail.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-auth-backend': patch +--- + +Inject optional `CatalogApi` into auth-backend `createRouter` function. This will enable developers to use customized `CatalogApi` when creating the router. From a74a0ff182efd69b33b4f2390ad54538c1190b58 Mon Sep 17 00:00:00 2001 From: kvmw Date: Mon, 7 Nov 2022 15:39:33 +0100 Subject: [PATCH 3/3] Updates api-report.md Signed-off-by: kvmw --- plugins/auth-backend/api-report.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/auth-backend/api-report.md b/plugins/auth-backend/api-report.md index cc6962cdbe..cec3422d9c 100644 --- a/plugins/auth-backend/api-report.md +++ b/plugins/auth-backend/api-report.md @@ -669,6 +669,8 @@ export const readState: (stateString: string) => OAuthState; // @public (undocumented) export interface RouterOptions { + // (undocumented) + catalogApi?: CatalogApi; // (undocumented) config: Config; // (undocumented)