mirror of
https://github.com/eliasstepanik/core.git
synced 2026-01-11 09:28:40 +00:00
31 lines
798 B
TypeScript
31 lines
798 B
TypeScript
export type AuthorizationAction = "read" | "write" | string; // Add more actions as needed
|
|
|
|
const ResourceTypes = ["spaces"] as const;
|
|
|
|
export type AuthorizationResources = {
|
|
[key in (typeof ResourceTypes)[number]]?: string | string[];
|
|
};
|
|
|
|
export type AuthorizationEntity = {
|
|
type: "PRIVATE";
|
|
scopes?: string[];
|
|
};
|
|
|
|
export type AuthorizationResult =
|
|
| { authorized: true }
|
|
| { authorized: false; reason: string };
|
|
|
|
/**
|
|
* Checks if the given entity is authorized to perform a specific action on a resource.
|
|
*/
|
|
export function checkAuthorization(
|
|
entity: AuthorizationEntity,
|
|
): AuthorizationResult {
|
|
// "PRIVATE" is a secret key and has access to everything
|
|
if (entity.type === "PRIVATE") {
|
|
return { authorized: true };
|
|
}
|
|
|
|
return { authorized: false, reason: "No key" };
|
|
}
|