How to use the @tsed/common.Authenticated function in @tsed/common

To help you get started, we’ve selected a few @tsed/common 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 / test / integration / app / controllers / calendars / EventCtrl.ts View on Github external
* @returns {null}
   */
  @Put("/:id")
  save(@BodyParams() event: EventModel): Promise | void {
    event.id = "1";

    return Promise.resolve(event);
  }

  /**
   *
   * @param event
   * @returns {null}
   */
  @Post("/list")
  @Authenticated({role: "admin"})
  @Returns(200, {use: EventModel, collection: Array})
  update(@BodyParams("event", EventModel) event: EventModel[]): EventModel[] {
    return event;
  }

  /**
   *
   * @returns {null}
   */
  @Delete("/:id")
  remove(): Promise | void {
    return Promise.resolve(null);
  }

  /**
   *
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
@Returns(CalendarModel)
  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 {
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
*
   * @param request
   * @param auth
   * @returns {{user: (number|any|string)}}
   */
  @Get("/middleware")
  @Use(CalendarCtrl.middleware)
  public getWithMiddleware(@Request() request: any, @HeaderParams("authorization") auth: string): any {
    return {
      user: request.user,
      token: auth
    };
  }

  @Get("/mvc")
  @Authenticated()
  @Use(CalendarCtrl.middleware)
  public testStackMiddlewares(@Request("user") user: any, @Locals("id") id: any, @Context("uid") uid: string): CalendarModel {
    const model = new CalendarModel();
    model.id = `${user}-${id}-${uid}`;
    model.name = "test";

    return model;
  }

  @Get("/middlewares2")
  @Authenticated()
  @UseAfter(CalendarCtrl.middleware2)
  public testUseAfter(@Request("user") user: any): Object {
    const model = new CalendarModel();
    model.id = user;
    model.name = "test";
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / TaskCtrl.ts View on Github external
import {Authenticated, Controller, Get, MergeParams, PathParams, QueryParams, UseBefore} from "@tsed/common";
import {Hidden} from "../../../../../packages/swagger/src";
import {Test2Middleware} from "../../middlewares/middleware";

@Controller("/:eventId/tasks")
@MergeParams()
@UseBefore(Test2Middleware)
@Authenticated({options: "options"})
export class TaskCtrl {
  @Get("/")
  async get(@PathParams("test") value: string, @PathParams("eventId") id: string) {
    return {value, id};
  }

  @Get("/hidden")
  @Hidden()
  async getHidden() {
    return {};
  }

  @Get("/hiddenparam")
  async getHiddenParams(
    @Hidden()
    @QueryParams("token")
github TypedProject / ts-express-decorators / test / integration / app / controllers / calendars / CalendarCtrl.ts View on Github external
};
  }

  @Get("/mvc")
  @Authenticated()
  @Use(CalendarCtrl.middleware)
  public testStackMiddlewares(@Request("user") user: any, @Locals("id") id: any, @Context("uid") uid: string): CalendarModel {
    const model = new CalendarModel();
    model.id = `${user}-${id}-${uid}`;
    model.name = "test";

    return model;
  }

  @Get("/middlewares2")
  @Authenticated()
  @UseAfter(CalendarCtrl.middleware2)
  public testUseAfter(@Request("user") user: any): Object {
    const model = new CalendarModel();
    model.id = user;
    model.name = "test";

    return model;
  }

  /**
   * Test the Header decorators.
   * @param request
   * @returns {{id: any, name: string}}
   */
  @Get("/headers")
  @Header("x-token-test", "test")
github TypedProject / ts-express-decorators / examples / getting-started / src / controllers / events / EventsCtrl.ts View on Github external
async update(@Required() @PathParams("calendarId") calendarId: string,
               @PathParams("id") id: string,
               @BodyParams("startDate") startDate: string,
               @BodyParams("endDate") endDate: string,
               @BodyParams("name") name: string): Promise {

    const event = await this.get(calendarId, id);
    event.name = name;
    event.startDate = name;
    event.endDate = name;

    return event;
  }

  @Delete("/:id")
  @Authenticated()
  @Status(204)
  async remove(@Required() @PathParams("calendarId") calendarId: string,
               @PathParams("id") id: string): Promise {
    this.events = this.events.filter(event => event.id === id && event.calendarId === calendarId);
  }

  @Get("/")
  async getEvents(@Required() @PathParams("calendarId") calendarId: string): Promise {
    return this.events.filter(event => event.calendarId === calendarId);
  }
}
github TypedProject / ts-express-decorators / examples / passportjs / src / controllers / calendars / CalendarCtrl.ts View on Github external
}

  /**
   *
   * @param id
   * @returns {{id: string, name: string}}
   */
  @Delete("/")
  @Authenticated()
  @Status(204)
  async remove(@BodyParams("id") @Required() id: string): Promise {
    this.calendarsService.remove(id);
  }

  @Get("/")
  @Authenticated()
  async getAllCalendars(): Promise {
    return this.calendarsService.query();
  }
}
github TypedProject / ts-express-decorators / examples / passportjs / src / controllers / calendars / CalendarCtrl.ts View on Github external
* @param name
   * @returns {Promise}
   */
  @Post("/:id")
  async update(@PathParams("id") @Required() id: string,
               @BodyParams("name") @Required() name: string): Promise {
    return this.calendarsService.update({id, name});
  }

  /**
   *
   * @param id
   * @returns {{id: string, name: string}}
   */
  @Delete("/")
  @Authenticated()
  @Status(204)
  async remove(@BodyParams("id") @Required() id: string): Promise {
    this.calendarsService.remove(id);
  }

  @Get("/")
  @Authenticated()
  async getAllCalendars(): Promise {
    return this.calendarsService.query();
  }
}