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"}),
Responses(403, {description: "Forbidden"}),
OAuthHead()
);
}
@BodyParams("name")
@Required()
name: string
): CalendarModel {
const model = new CalendarModel();
model.id = "2";
model.name = "test";
return model;
}
@Delete("/")
@Status(204)
@Authenticated({role: "admin"})
@Security("global_auth", "read:global")
@Security("calendar_auth", "write:calendar", "read:calendar")
public remove(
@BodyParams("id")
@Required()
id: string
): void {
return undefined;
}
@Delete("/token")
@Status(204)
@OAuth({role: "admin", scopes: ["write:calendar", "read:calendar"]})
public removeWithToken(@BodyParams("id") @Required() id: string): void {
return undefined;
}
public save(
@BodyParams("name")
@Required()
name: string
): CalendarModel {
const model = new CalendarModel();
model.id = "2";
model.name = "test";
return model;
}
@Delete("/")
@Status(204)
@Authenticated({role: "admin"})
@Security("global_auth", "read:global")
@Security("calendar_auth", "write:calendar", "read:calendar")
public remove(
@BodyParams("id")
@Required()
id: string
): void {
return undefined;
}
@Delete("/token")
@Status(204)
@OAuth({role: "admin", scopes: ["write:calendar", "read:calendar"]})
public removeWithToken(@BodyParams("id") @Required() id: string): void {
return undefined;
export function CustomAuth(options: ICustomAuthOptions = {}): Function {
return applyDecorators(
UseAuth(CustomAuthMiddleware, options),
Security("oauth", ...(options.scopes || [])),
Responses(401, {description: "Unauthorized"}),
Responses(403, {description: "Forbidden"})
);
}