@loopback/authorization
Version:
A LoopBack component for authorization support.
74 lines (73 loc) • 3.63 kB
TypeScript
import { BindingAddress, MetadataAccessor, MetadataMap, MethodDecoratorFactory } from '@loopback/core';
import { AuthorizationMetadata, Authorizer } from '../types';
export declare const AUTHORIZATION_METHOD_KEY: MetadataAccessor<AuthorizationMetadata, MethodDecorator>;
export declare const AUTHORIZATION_CLASS_KEY: MetadataAccessor<AuthorizationMetadata, ClassDecorator>;
export declare class AuthorizeMethodDecoratorFactory extends MethodDecoratorFactory<AuthorizationMetadata> {
protected mergeWithOwn(ownMetadata: MetadataMap<AuthorizationMetadata>, target: Object, methodName?: string, methodDescriptor?: TypedPropertyDescriptor<any> | number): MetadataMap<AuthorizationMetadata>;
private merge;
}
/**
* Decorator `@authorize` to mark methods that require authorization
*
* @param spec Authorization metadata
*/
export declare function authorize(spec: AuthorizationMetadata): (target: any, method?: string, methodDescriptor?: TypedPropertyDescriptor<any>) => any;
export declare namespace authorize {
/**
* Shortcut to configure allowed roles
* @param roles
*/
const allow: (...roles: string[]) => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Shortcut to configure denied roles
* @param roles
*/
const deny: (...roles: string[]) => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Shortcut to specify access scopes
* @param scopes
*/
const scope: (...scopes: string[]) => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Shortcut to configure voters
* @param voters
*/
const vote: (...voters: (Authorizer | BindingAddress<Authorizer>)[]) => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Allows all
*/
const allowAll: () => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Allow all but the given roles
* @param roles
*/
const allowAllExcept: (...roles: string[]) => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Deny all
*/
const denyAll: () => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Deny all but the given roles
* @param roles
*/
const denyAllExcept: (...roles: string[]) => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Allow authenticated users
*/
const allowAuthenticated: () => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Deny unauthenticated users
*/
const denyUnauthenticated: () => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
/**
* Skip authorization
*/
const skip: () => (target: any, method?: string | undefined, methodDescriptor?: TypedPropertyDescriptor<any> | undefined) => any;
}
/**
* Fetch authorization metadata stored by `@authorize` decorator.
*
* @param target Target object/class
* @param methodName Target method
*/
export declare function getAuthorizationMetadata(target: object, methodName: string): AuthorizationMetadata | undefined;