Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"}),
Responses(403, {description: "Forbidden"}),
OAuthHead()
);
}
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"}),
Responses(403, {description: "Forbidden"}),
OAuthHead()
);
}
})
@MergeParams()
export class EventCtrl extends BaseController {
/**
*
*/
@Head("/")
head() {
}
/**
*
* @returns {string}
*/
@Patch("/:id")
@Responses("404", {description: "Not found"})
patch(
@Title("Title event")
@Required()
@BodyParams()
event: EventModel
): EventModel {
if (event.id === "0" || event.id === "") {
throw new NotFound("Not found");
}
return event;
}
/**
*
* @param response
import {Controller, Put, Status} from "@tsed/common";
import {MulterOptions, MultipartFile} from "@tsed/multipartfiles";
import {Responses} from "@tsed/swagger";
@Controller("/upload")
export class UploadController {
constructor() {
}
@Put("/")
@Status(201)
@Responses("201", {description: "Created"})
@Responses("400", {description: "Bad Request"})
@MulterOptions({dest: `${process.cwd()}/.tmp`})
async add(@MultipartFile("file") file: Express.Multer.File): Promise {
console.log("file: ", file);
return true;
}
}
import {Controller, Put, Status} from "@tsed/common";
import {MulterOptions, MultipartFile} from "@tsed/multipartfiles";
import {Responses} from "@tsed/swagger";
@Controller("/upload")
export class UploadController {
constructor() {
}
@Put("/")
@Status(201)
@Responses("201", {description: "Created"})
@Responses("400", {description: "Bad Request"})
@MulterOptions({dest: `${process.cwd()}/.tmp`})
async add(@MultipartFile("file") file: Express.Multer.File): Promise {
console.log("file: ", file);
return true;
}
}
export function CustomAuth(options: ICustomAuthOptions = {}): Function {
return applyDecorators(
UseAuth(CustomAuthMiddleware, options),
Security("oauth", ...(options.scopes || [])),
Responses(401, {description: "Unauthorized"}),
Responses(403, {description: "Forbidden"})
);
}
export function CustomAuth(options: ICustomAuthOptions = {}): Function {
return applyDecorators(
UseAuth(CustomAuthMiddleware, options),
Security("oauth", ...(options.scopes || [])),
Responses(401, {description: "Unauthorized"}),
Responses(403, {description: "Forbidden"})
);
}