import { SecurityContext , SecurityIdentity , SecurityPermission } from "~/types" ; import { ContextPlugin } from "@webiny/handler" ; export interface Config { identityType ? : string ; } interface APIKeyIdentity extends SecurityIdentity { permissions : SecurityPermission [ ] ; } export default ( config ) => { return new ContextPlugin < SecurityContext < APIKeyIdentity > > ( ( { security } ) => { security . addAuthorizer ( async ( ) => { const identityType = config . identityType || "api-key" ; const identity = security . getIdentity ( ) ; if ( ! identity || identity . type !== identityType ) { return ; } return Array . isArray ( identity . permissions ) ? identity . permissions : [ ] ; } ) ; } ) ; } ;