Use request options

This commit is contained in:
Erik Larsson
2021-01-27 02:30:33 +01:00
parent 7d7fe3d788
commit 97d13a8889
3 changed files with 11 additions and 6 deletions
@@ -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(
@@ -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<string, string>;
@@ -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<UserEntity> {
const token = options?.token;
const filter: Record<string, string> = {
kind: 'user',
};
@@ -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,