How to use the @tsed/swagger.Security function in @tsed/swagger

To help you get started, we’ve selected a few @tsed/swagger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / decorators / OAuthBearer.ts View on Github external
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()
  );
}
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
@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;
  }
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
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;
github TypedProject / ts-express-decorators / docs / docs / snippets / authentication / auth-decorator-example.ts View on Github external
export function CustomAuth(options: ICustomAuthOptions = {}): Function {
  return applyDecorators(
    UseAuth(CustomAuthMiddleware, options),
    Security("oauth", ...(options.scopes || [])),
    Responses(401, {description: "Unauthorized"}),
    Responses(403, {description: "Forbidden"})
  );
}