From 97d13a88896e63e831303a954f688fe512685ed0 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2021 02:30:33 +0100 Subject: [PATCH] Use request options --- .../src/lib/catalog/CatalogIdentityClient.test.ts | 2 +- .../src/lib/catalog/CatalogIdentityClient.ts | 4 +++- plugins/auth-backend/src/providers/google/provider.ts | 11 +++++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts index 9137af5e83..7eb50c92bf 100644 --- a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts +++ b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.test.ts @@ -30,7 +30,7 @@ describe('CatalogIdentityClient', () => { catalogClient: new MockedCatalogClient(), }); - client.findUser(token, { annotations: { key: 'value' } }); + client.findUser({ annotations: { key: 'value' } }, { token }); const getEntities = MockedCatalogClient.mock.instances[0].getEntities; expect(getEntities).toHaveBeenCalledWith( diff --git a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts index 9967a7be17..6c052321a1 100644 --- a/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts +++ b/plugins/auth-backend/src/lib/catalog/CatalogIdentityClient.ts @@ -17,6 +17,7 @@ import { ConflictError, NotFoundError } from '@backstage/backend-common'; import { CatalogClient } from '@backstage/catalog-client'; import { UserEntity } from '@backstage/catalog-model'; +import { CatalogIdentityRequestOptions } from './types'; type UserQuery = { annotations: Record; @@ -38,9 +39,10 @@ export class CatalogIdentityClient { * Throws a NotFoundError or ConflictError if 0 or multiple users are found. */ async findUser( - token: string | undefined, query: UserQuery, + options?: CatalogIdentityRequestOptions, ): Promise { + const token = options?.token; const filter: Record = { kind: 'user', }; diff --git a/plugins/auth-backend/src/providers/google/provider.ts b/plugins/auth-backend/src/providers/google/provider.ts index 340ec46529..15c2172e6e 100644 --- a/plugins/auth-backend/src/providers/google/provider.ts +++ b/plugins/auth-backend/src/providers/google/provider.ts @@ -157,11 +157,14 @@ export class GoogleAuthProvider implements OAuthHandlers { const token = await this.tokenIssuer.issueToken({ claims: { sub: 'backstage.io/auth-backend' }, }); - const user = await this.identityClient.findUser(token, { - annotations: { - 'google.com/email': profile.email, + const user = await this.identityClient.findUser( + { + annotations: { + 'google.com/email': profile.email, + }, }, - }); + { token }, + ); return { ...response,