auth: rename issuedBy to actor

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2025-04-09 15:58:20 +02:00
parent dcc5f2b3cc
commit 7a88f85f2f
6 changed files with 16 additions and 17 deletions
@@ -87,7 +87,6 @@ export class DefaultAuthService implements AuthService {
userResult.userEntityRef,
token,
this.#getJwtExpiration(token),
this.pluginId,
);
}
@@ -51,7 +51,7 @@ export function createCredentialsWithUserPrincipal(
sub: string,
token: string,
expiresAt?: Date,
issuedBySubject?: string,
actor?: string,
): InternalBackstageCredentials<BackstageUserPrincipal> {
return Object.defineProperty(
{
@@ -61,8 +61,8 @@ export function createCredentialsWithUserPrincipal(
principal: {
type: 'user',
userEntityRef: sub,
...(issuedBySubject && {
issuedBy: { type: 'service', subject: issuedBySubject },
...(actor && {
actor: { type: 'service', subject: actor },
}),
},
},
@@ -45,7 +45,7 @@ export type BackstageUserPrincipal = {
* of a user. It provides context about the intermediary service that
* facilitated the authentication.
*/
issuedBy?: BackstageServicePrincipal;
actor?: BackstageServicePrincipal;
};
/**
@@ -73,11 +73,11 @@ export class MockAuthService implements AuthService {
}
if (token.startsWith(MOCK_USER_TOKEN_PREFIX)) {
const { sub: userEntityRef, issuedBy }: UserTokenPayload = JSON.parse(
const { sub: userEntityRef, actor }: UserTokenPayload = JSON.parse(
token.slice(MOCK_USER_TOKEN_PREFIX.length),
);
return mockCredentials.user(userEntityRef, { issuedBySubject: issuedBy });
return mockCredentials.user(userEntityRef, { actor });
}
if (token.startsWith(MOCK_USER_LIMITED_TOKEN_PREFIX)) {
@@ -55,7 +55,7 @@ function validateUserEntityRef(ref: string) {
*/
export type UserTokenPayload = {
sub?: string;
issuedBy?: string;
actor?: { subject: string };
};
/**
@@ -108,7 +108,7 @@ export namespace mockCredentials {
*/
export function user(
userEntityRef: string = DEFAULT_MOCK_USER_ENTITY_REF,
options?: { issuedBySubject?: string },
options?: { actor?: string },
): BackstageCredentials<BackstageUserPrincipal> {
validateUserEntityRef(userEntityRef);
return {
@@ -116,8 +116,8 @@ export namespace mockCredentials {
principal: {
type: 'user',
userEntityRef,
...(options?.issuedBySubject && {
issuedBy: { type: 'service', subject: options.issuedBySubject },
...(options?.actor && {
actor: { type: 'service', subject: options.actor.subject },
}),
},
};
@@ -134,14 +134,14 @@ export namespace mockCredentials {
*/
export function token(
userEntityRef?: string,
options?: { issuedBySubject?: string },
options?: { actor?: string },
): string {
if (userEntityRef) {
validateUserEntityRef(userEntityRef);
return `${MOCK_USER_TOKEN_PREFIX}${JSON.stringify({
sub: userEntityRef,
...(options?.issuedBySubject && {
issuedBy: options.issuedBySubject,
...(options?.actor && {
actor: options.actor,
}),
} satisfies UserTokenPayload)}`;
}
@@ -596,7 +596,7 @@ describe('createRouter', () => {
expect(mockApplyConditions).toHaveBeenCalledWith(
'plugin-1',
mockCredentials.user('user:default/spiderman', {
issuedBySubject: 'some-service',
actor: 'some-service',
}),
[
expect.objectContaining({
@@ -611,7 +611,7 @@ describe('createRouter', () => {
expect(mockApplyConditions).toHaveBeenCalledWith(
'plugin-2',
mockCredentials.user('user:default/spiderman', {
issuedBySubject: 'some-service',
actor: 'some-service',
}),
[
expect.objectContaining({
@@ -729,7 +729,7 @@ describe('createRouter', () => {
function userTokenIssuedByService() {
return mockCredentials.user.token('user:default/spiderman', {
issuedBySubject: 'some-service',
actor: 'some-service',
});
}
});