backend-*-api: updates auth APIs for BEP changes

Co-authored-by: Fredrik Adelöw <freben@gmail.com>
Co-authored-by: Camila Belo <camilaibs@gmail.com>
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-02-15 14:45:08 +01:00
parent 05b7e91861
commit 413a9e7de8
11 changed files with 65 additions and 76 deletions
@@ -44,7 +44,7 @@ export class MockAuthService implements AuthService {
throw new AuthenticationError('Invalid token');
}
async getOwnCredentials(): Promise<
async getOwnServiceCredentials(): Promise<
BackstageCredentials<BackstageServicePrincipal>
> {
return {
@@ -68,10 +68,11 @@ export class MockAuthService implements AuthService {
return true;
}
async issueServiceToken(options: {
forward: BackstageCredentials;
async getPluginRequestToken(options: {
onBehalfOf: BackstageCredentials;
targetPluginId: string;
}): Promise<{ token: string }> {
const principal = options.forward.principal as
const principal = options.onBehalfOf.principal as
| BackstageUserPrincipal
| BackstageServicePrincipal
| BackstageNonePrincipal;
@@ -80,7 +81,7 @@ export class MockAuthService implements AuthService {
case 'user':
return { token: 'mock-user-token' };
case 'service':
return { token: 'mock-service-token' };
return { token: `mock-service-token-for-${options.targetPluginId}` };
default:
throw new AuthenticationError(
`Refused to issue service token for credential type '${principal.type}'`,
@@ -180,9 +180,9 @@ export namespace mockServices {
});
export const mock = simpleMock(coreServices.auth, () => ({
authenticate: jest.fn(),
getOwnCredentials: jest.fn(),
getOwnServiceCredentials: jest.fn(),
isPrincipal: jest.fn() as any,
issueServiceToken: jest.fn(),
getPluginRequestToken: jest.fn(),
}));
}
@@ -217,7 +217,6 @@ export namespace mockServices {
export const mock = simpleMock(coreServices.httpAuth, () => ({
credentials: jest.fn(),
issueUserCookie: jest.fn(),
requestHeaders: jest.fn(),
}));
}