permission-node: update policy handler to work with new auth system

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2024-07-12 13:39:40 +02:00
parent 1a966daca7
commit ed10fd202c
15 changed files with 127 additions and 66 deletions
+1 -1
View File
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export type { PermissionPolicy, PolicyQuery } from './types';
export type { PermissionPolicy, PolicyQuery, PolicyQueryUser } from './types';
+44 -5
View File
@@ -18,7 +18,11 @@ import {
Permission,
PolicyDecision,
} from '@backstage/plugin-permission-common';
import { BackstageIdentityResponse } from '@backstage/plugin-auth-node';
import { BackstageUserIdentity } from '@backstage/plugin-auth-node';
import {
BackstageCredentials,
BackstageUserInfo,
} from '@backstage/backend-plugin-api';
/**
* A query to be evaluated by the {@link PermissionPolicy}.
@@ -34,6 +38,44 @@ export type PolicyQuery = {
permission: Permission;
};
/**
* The context within which a policy query is evaluated.
*
* @public
*/
export type PolicyQueryUser = {
/**
* The token used to authenticate the user within Backstage.
*
* @deprecated User the `credentials` field in combination with `coreServices.auth` to generate a request token instead.
*/
token: string;
/**
* The number of seconds until the token expires. If not set, it can be assumed that the token does not expire.
*
* @deprecated This field is deprecated and will be removed in a future release.
*/
expiresInSeconds?: number;
/**
* A plaintext description of the identity that is encapsulated within the token.
*
* @deprecated Use the `info` field instead.
*/
identity: BackstageUserIdentity;
/**
* The credentials of the user making the request.
*/
credentials: BackstageCredentials;
/**
* The information for the user making the request.
*/
info: BackstageUserInfo;
};
/**
* A policy to evaluate authorization requests for any permissioned action performed in Backstage.
*
@@ -51,8 +93,5 @@ export type PolicyQuery = {
* @public
*/
export interface PermissionPolicy {
handle(
request: PolicyQuery,
user?: BackstageIdentityResponse,
): Promise<PolicyDecision>;
handle(request: PolicyQuery, user?: PolicyQueryUser): Promise<PolicyDecision>;
}