Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function OAuthBearer(options: any = {}): Function {
return applyDecorators(
AuthOptions(OAuthBearerOptions as any, options), // Add this to store all options and retrieve it in verify function
UseAuth(Passport.authenticate("oauth-bearer", {session: false, ...options}) as any),
// Metadata for swagger
Security("oauth", ...(options.scopes || [])),
Operation({
"parameters": [
{
"in": "header",
"name": "Authorization",
"type": "string",
"required": true
}
]
}),
Responses(401, {description: "Unauthorized"}),
export function SocketService(namespace = "/") {
return applyDecorators(StoreMerge("socketIO", {namespace, type: SocketProviderTypes.SERVICE}), (target: Type) => {
registerSocketService(target);
});
}
export function Ref(model: string | any, type: MongooseSchemaTypes = MongooseSchemaTypes.OBJECT_ID) {
return applyDecorators(
Property({use: String}),
Schema({
type: String,
example: "5ce7ad3028890bd71749d477",
description: "Mongoose Ref ObjectId"
}),
StoreFn((store: Store) => {
delete store.get("schema").$ref;
}),
StoreMerge(MONGOOSE_SCHEMA, {
type: MongooseSchema.Types[type],
ref: typeof model === "string" ? model : Store.from(model).get(MONGOOSE_MODEL_NAME)
})
);
}
export function Status(code: number, options: IResponseOptions = {}) {
const response = mapReturnedResponse(options);
return applyDecorators(
StoreSet("statusCode", code),
StoreMerge("response", response),
StoreMerge("responses", {[code]: response}),
UseAfter((request: any, response: any, next: any) => {
if (response.statusCode === 200) {
response.status(code);
}
next();
})
);
}
export function Required(...allowedRequiredValues: any[]): any {
return applyDecorators(
(...decoratorArgs: DecoratorParameters) => {
const metadata = getStorableMetadata(decoratorArgs);
if (!metadata) {
throw new UnsupportedDecoratorType(Required, decoratorArgs);
}
metadata.required = true;
if (allowedRequiredValues.length) {
Allow(...allowedRequiredValues)(...decoratorArgs);
}
},
StoreMerge("responses", {
"400": {
description: "BadRequest"
export function ObjectID(name?: string) {
return applyDecorators(
Property({name, use: String}),
Schema({
description: "Mongoose ObjectId",
example: "5ce7ad3028890bd71749d477"
})
);
}
return (...args: DecoratorParameters): TypedPropertyDescriptor | void => {
switch (getDecoratorType(args, true)) {
case "method":
return applyDecorators(
StoreFn((store: Store) => {
if (!store.has(guardAuth)) {
return UseBefore(guardAuth);
}
}),
AuthOptions(guardAuth, options)
)(...args);
case "class":
decorateMethodsOf(args[0], UseAuth(guardAuth, options));
break;
default:
throw new UnsupportedDecoratorType(UseAuth, args);
}
};
export function ResponseView(viewPath: string, viewOptions?: Object): Function {
return applyDecorators(StoreSet(ResponseViewMiddleware, {viewPath, viewOptions}), UseAfter(ResponseViewMiddleware));
}
export function ContentType(type: string) {
return applyDecorators(
StoreMerge("produces", [type]),
UseAfter((request: any, response: any, next: any) => {
response.type(type);
next();
})
);
}
return (...parameters: any[]) => {
switch (getDecoratorType(parameters)) {
case "property":
return applyDecorators(Property(), StoreMerge(MONGOOSE_SCHEMA, options))(...parameters);
case "class":
StoreMerge(MONGOOSE_SCHEMA, createSchema(parameters[0], options as MongooseSchemaOptions))(...parameters);
break;
}
};
}