Merge pull request #28984 from backstage/rugvip/defaults

auth-backend: move getDefaultOwnershipEntityRefs to resolver context
This commit is contained in:
Patrik Oldsberg
2025-02-27 18:43:45 +01:00
committed by GitHub
9 changed files with 66 additions and 19 deletions
+1 -1
View File
@@ -216,7 +216,7 @@ export type GcpIapResult = GcpIapResult_2;
// @public @deprecated
export type GcpIapTokenInfo = GcpIapTokenInfo_2;
// @public
// @public @deprecated
export function getDefaultOwnershipEntityRefs(entity: Entity): string[];
// @public @deprecated (undocumented)
@@ -46,6 +46,7 @@ import { CatalogIdentityClient } from '../catalog';
* A reference to the entity itself will also be included in the returned array.
*
* @public
* @deprecated use `ctx.resolveOwnershipEntityRefs(entity)` from the provided `AuthResolverContext` instead.
*/
export function getDefaultOwnershipEntityRefs(entity: Entity) {
const membershipRefs =
@@ -164,21 +165,26 @@ export class CatalogAuthResolverContext implements AuthResolverContext {
async signInWithCatalogUser(query: AuthResolverCatalogUserQuery) {
const { entity } = await this.findCatalogUser(query);
let ent: string[];
if (this.ownershipResolver) {
const { ownershipEntityRefs } =
await this.ownershipResolver.resolveOwnershipEntityRefs(entity);
ent = ownershipEntityRefs;
} else {
ent = getDefaultOwnershipEntityRefs(entity);
}
const { ownershipEntityRefs } = await this.resolveOwnershipEntityRefs(
entity,
);
const token = await this.tokenIssuer.issueToken({
claims: {
sub: stringifyEntityRef(entity),
ent,
ent: ownershipEntityRefs,
},
});
return { token };
}
async resolveOwnershipEntityRefs(
entity: Entity,
): Promise<{ ownershipEntityRefs: string[] }> {
if (this.ownershipResolver) {
return this.ownershipResolver.resolveOwnershipEntityRefs(entity);
}
return { ownershipEntityRefs: getDefaultOwnershipEntityRefs(entity) };
}
}
@@ -119,6 +119,7 @@ describe('oidc.create', () => {
issueToken: jest.fn(),
findCatalogUser: jest.fn(),
signInWithCatalogUser: jest.fn(),
resolveOwnershipEntityRefs: jest.fn(),
},
};
});