authorize({ action, resourceFactory }) {
        const actionTokens = action.split(':');
        return async (req, res, next) => {
            const resource = resourceFactory(req);
            try {
                if (!req.fusebit.caller.permissions) {
                    throw new Error('The caller was not authenticated.');
                }
                for (const permission of req.fusebit.caller.permissions.allow) {
                    if (resource.indexOf(permission.resource) !== 0) {
                        continue;
                    }
                    const actualActionTokens = permission.action.split(':');
                    let match = true;
                    for (let i = 0; i < actionTokens.length; i++) {
                        if (actionTokens[i] !== actualActionTokens[i]) {
                            match = actualActionTokens[i] === '*';
                            break;
                        }
                    }
                    if (match) {
                        return next();
                    }
                }
                throw new Error('Caller does not have sufficient permissions.');
            } catch (e) {
                Sdk.debug('FAILED AUTHORIZATION CHECK', e.message, action, resource, req.fusebit.caller.permissions);
                res.status(403).send({ status: 403, statusCode: 403, message: 'Unauthorized' });
                return;
            }
        };
    }
/**
     * Creates Express middleware that authorizes the call using Fusebit security. For example, the following will only execute
     * the Express handler if the access token supplied by the caller has the function:execute permission on the function resource.
     *
     * app.get('/myendpoint',
     *   authorize({
     *     action: 'function:execute',
     *     resourceFactory: req => `/account/${req.fusebit.accountId}/subscription/${req.fusebit.subscriptionId}/boundary/${req.fusebit.boundaryId}/function/${req.fusebit.functionId}/myendpoint/`
     *   }),
     *   handler
     * );
     *
     * @param {object} param Object with action and resourceFactory properties
     */
Creates Express middleware that authorizes the call using Fusebit security. For example, the following will only execute
the Express handler if the access token supplied by the caller has the function:execute permission on the function resource.



@param {object} param Object with action and resourceFactory properties
Creates Express middleware that authorizes the call using Fusebit security . For example the following will only execute the Express handler if the access token supplied by the caller has the function : execute permission on the function resource . @param { object } param Object with action and resourceFactory properties
authorize({ action, resourceFactory }) {
        const actionTokens = action.split(':');
        return async (req, res, next) => {
            const resource = resourceFactory(req);
            try {
                if (!req.fusebit.caller.permissions) {
                    throw new Error('The caller was not authenticated.');
                }
                for (const permission of req.fusebit.caller.permissions.allow) {
                    if (resource.indexOf(permission.resource) !== 0) {
                        continue;
                    }
                    const actualActionTokens = permission.action.split(':');
                    let match = true;
                    for (let i = 0; i < actionTokens.length; i++) {
                        if (actionTokens[i] !== actualActionTokens[i]) {
                            match = actualActionTokens[i] === '*';
                            break;
                        }
                    }
                    if (match) {
                        return next();
                    }
                }
                throw new Error('Caller does not have sufficient permissions.');
            } catch (e) {
                Sdk.debug('FAILED AUTHORIZATION CHECK', e.message, action, resource, req.fusebit.caller.permissions);
                res.status(403).send({ status: 403, statusCode: 403, message: 'Unauthorized' });
                return;
            }
        };
    }
authorize ( { action , resourceFactory } ) { const actionTokens = action . split ( ':' ) ; return async ( req , res , next ) => { const resource = resourceFactory ( req ) ; try { if ( ! req . fusebit . caller . permissions ) { throw new Error ( 'The caller was not authenticated.' ) ; } for ( const permission of req . fusebit . caller . permissions . allow ) { if ( resource . indexOf ( permission . resource ) !== 0 ) { continue ; } const actualActionTokens = permission . action . split ( ':' ) ; let match = true ; for ( let i = 0 ; i < actionTokens . length ; i ++ ) { if ( actionTokens [ i ] !== actualActionTokens [ i ] ) { match = actualActionTokens [ i ] === '*' ; break ; } } if ( match ) { return next ( ) ; } } throw new Error ( 'Caller does not have sufficient permissions.' ) ; } catch ( e ) { Sdk . debug ( 'FAILED AUTHORIZATION CHECK' , e . message , action , resource , req . fusebit . caller . permissions ) ; res . status ( 403 ) . send ( { status : 403 , statusCode : 403 , message : 'Unauthorized' } ) ; return ; } } ; }
Creates Express middleware that authorizes the call using Fusebit security.
Creates Express middleware that authorizes the call using Fusebit security .