Fix Permission / AppPermission (#220)

This commit is contained in:
Lukasz Ostrowski 2023-03-16 15:03:35 +01:00 committed by GitHub
parent 7c790e44a2
commit 96ffb925bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 14 deletions

View file

@ -0,0 +1,5 @@
---
"@saleor/app-sdk": patch
---
Restores MANAGE_APPS to Permissions, but remove it from AppPermissions

View file

@ -2,7 +2,7 @@ import { NextApiHandler, NextApiRequest, NextApiResponse } from "next";
import { APL } from "../../APL";
import { createDebug } from "../../debug";
import { AppPermission } from "../../types";
import { Permission } from "../../types";
import {
processSaleorProtectedHandler,
ProtectedHandlerError,
@ -37,7 +37,7 @@ export const createProtectedHandler =
(
handlerFn: NextProtectedApiHandler,
apl: APL,
requiredPermissions?: AppPermission[]
requiredPermissions?: Permission[]
): NextApiHandler =>
(req, res) => {
debug("Protected handler called");

View file

@ -4,7 +4,7 @@ import { APL } from "../../APL";
import { AuthData } from "../../APL/apl";
import { createDebug } from "../../debug";
import { getBaseUrl, getSaleorHeaders } from "../../headers";
import { AppPermission } from "../../types";
import { Permission } from "../../types";
import { verifyJWT } from "../../verify-jwt";
const debug = createDebug("processProtectedHandler");
@ -39,7 +39,7 @@ export type ProtectedHandlerContext = {
interface ProcessSaleorProtectedHandlerArgs {
req: NextApiRequest;
apl: APL;
requiredPermissions?: AppPermission[];
requiredPermissions?: Permission[];
}
type ProcessAsyncSaleorProtectedHandler = (

View file

@ -1,12 +1,12 @@
import { createDebug } from "./debug";
import { AppPermission } from "./types";
import { Permission } from "./types";
import { DashboardTokenPayload } from "./verify-jwt";
const debug = createDebug("checkJwtPermissions");
export const hasPermissionsInJwtToken = (
tokenData?: Pick<DashboardTokenPayload, "user_permissions">,
permissionsToCheckAgainst?: AppPermission[]
permissionsToCheckAgainst?: Permission[]
) => {
debug(`Permissions required ${permissionsToCheckAgainst}`);

View file

@ -15,7 +15,7 @@ export type AppExtensionMount =
| "ORDER_OVERVIEW_MORE_ACTIONS";
/**
* TODO: Extract from Saleor graphQL schema
* All permissions that users can have
* Reference https://docs.saleor.io/docs/3.x/api-reference/enums/permission-enum
*/
export type Permission =
@ -40,9 +40,13 @@ export type Permission =
| "MANAGE_PRODUCT_TYPES_AND_ATTRIBUTES"
| "MANAGE_SHIPPING"
| "MANAGE_SETTINGS"
| "MANAGE_TRANSLATIONS";
| "MANAGE_TRANSLATIONS"
| "MANAGE_APPS";
export type AppPermission = Permission;
/**
* All permissions that App can have.
*/
export type AppPermission = Exclude<Permission, "MANAGE_APPS">;
/**
* @see https://github.com/saleor/saleor/blob/main/saleor/graphql/schema.graphql#L1505

View file

@ -1,10 +1,10 @@
import * as jose from "jose";
import { AppPermission } from "../types";
import { Permission } from "../types";
type TokenUserPayload = {
email: string;
userPermissions: AppPermission[];
userPermissions: Permission[];
};
export const extractUserFromJwt = (jwtToken: string): TokenUserPayload => {

View file

@ -2,21 +2,21 @@ import * as jose from "jose";
import { createDebug } from "./debug";
import { hasPermissionsInJwtToken } from "./has-permissions-in-jwt-token";
import { AppPermission } from "./types";
import { Permission } from "./types";
import { getJwksUrlFromSaleorApiUrl } from "./urls";
const debug = createDebug("verify-jwt");
export interface DashboardTokenPayload extends jose.JWTPayload {
app: string;
user_permissions: AppPermission[];
user_permissions: Permission[];
}
export interface verifyJWTArguments {
appId: string;
saleorApiUrl: string;
token: string;
requiredPermissions?: AppPermission[];
requiredPermissions?: Permission[];
}
export const verifyJWT = async ({