How to use the typescript-rest.Security function in typescript-rest

To help you get started, we’ve selected a few typescript-rest 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 thiagobustamante / typescript-rest-swagger / test / data / apis.ts View on Github external
export class NamedEntity implements Entity {
    public id: number;
    public name: string;
}

@Path('abstract')
export class AbstractEntityEndpoint {
    @GET
    public get(): NamedEntity {
        return new NamedEntity();
    }
}

@Path('secure')
@Security(['ROLE_1', 'ROLE_2'], 'access_token')
export class SecureEndpoint {
    @GET
    public get(): string {
        return 'Access Granted';
    }

    @POST
    @Security([], 'user_email')
    public post(): string {
        return 'Posted';
    }
}

@Path('supersecure')
@Security('access_token')
@Security('user_email')
github thiagobustamante / typescript-rest-swagger / test / data / apis.ts View on Github external
export class SecureEndpoint {
    @GET
    public get(): string {
        return 'Access Granted';
    }

    @POST
    @Security([], 'user_email')
    public post(): string {
        return 'Posted';
    }
}

@Path('supersecure')
@Security('access_token')
@Security('user_email')
@Security()
export class SuperSecureEndpoint {
    @GET
    public get(): string {
        return 'Access Granted';
    }
}

@Path('response')
@swagger.Response(400, 'The request format was incorrect.')
@swagger.Response(500, 'There was an unexpected error.')
export class ResponseController {
    @GET
    public get(): string {
        return '42';
    }
github thiagobustamante / typescript-rest-swagger / test / data / apis.ts View on Github external
@GET
    public get(): string {
        return 'Access Granted';
    }

    @POST
    @Security([], 'user_email')
    public post(): string {
        return 'Posted';
    }
}

@Path('supersecure')
@Security('access_token')
@Security('user_email')
@Security()
export class SuperSecureEndpoint {
    @GET
    public get(): string {
        return 'Access Granted';
    }
}

@Path('response')
@swagger.Response(400, 'The request format was incorrect.')
@swagger.Response(500, 'There was an unexpected error.')
export class ResponseController {
    @GET
    public get(): string {
        return '42';
    }
github turt2live / matrix-dimension / src / api / admin / AdminTermsService.ts View on Github external
@Path(":shortcode/draft")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async createDraftPolicy(@PathParam("shortcode") shortcode: string, request: CreatePolicyObject): Promise {
        return this.termsController.createDraftPolicy(request.name, shortcode, request.text, request.url);
    }

    @POST
    @Path(":shortcode/publish/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async publishDraftPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise {
        return this.termsController.publishPolicy(shortcode, version);
    }

    @PUT
    @Path(":shortcode/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async updatePolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string, request: CreatePolicyObject): Promise {
        return this.termsController.updatePolicy(request.name, shortcode, version, request.text, request.url);
    }
}
github turt2live / matrix-dimension / src / api / msc / MSCAccountService.ts View on Github external
@Inject
    private accountController: AccountController;

    @Context
    private context: ServiceContext;

    @POST
    @Path("register")
    public async register(request: OpenId): Promise {
        return this.accountController.registerAccount(request);
    }

    @GET
    @Path("")
    @Security(ROLE_MSC_USER)
    public async info(): Promise {
        const user: IMSCUser = this.context.request.user;
        return {user_id: user.userId};
    }

    @POST
    @Path("logout")
    @Security(ROLE_MSC_USER)
    public async logout(): Promise {
        await this.accountController.logout(this.context.request.user);
        return {};
    }
}
github turt2live / matrix-dimension / src / api / admin / AdminTermsService.ts View on Github external
url: string;
}

/**
 * Administrative API for configuring terms of service.
 */
@Path("/api/v1/dimension/admin/terms")
@AutoWired
export class AdminTermsService {

    @Inject
    private termsController: TermsController;

    @GET
    @Path("all")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async getPolicies(): Promise {
        return this.termsController.getPoliciesForAdmin();
    }

    @GET
    @Path(":shortcode/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async getPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise {
        return this.termsController.getPolicyForAdmin(shortcode, version);
    }

    @POST
    @Path(":shortcode/draft")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async createDraftPolicy(@PathParam("shortcode") shortcode: string, request: CreatePolicyObject): Promise {
        return this.termsController.createDraftPolicy(request.name, shortcode, request.text, request.url);
github turt2live / matrix-dimension / src / api / msc / MSCAccountService.ts View on Github external
@Path("register")
    public async register(request: OpenId): Promise {
        return this.accountController.registerAccount(request);
    }

    @GET
    @Path("")
    @Security(ROLE_MSC_USER)
    public async info(): Promise {
        const user: IMSCUser = this.context.request.user;
        return {user_id: user.userId};
    }

    @POST
    @Path("logout")
    @Security(ROLE_MSC_USER)
    public async logout(): Promise {
        await this.accountController.logout(this.context.request.user);
        return {};
    }
}
github turt2live / matrix-dimension / src / api / matrix / MatrixTermsService.ts View on Github external
@Inject
    private termsController: TermsController;

    @Context
    private context: ServiceContext;

    @GET
    @Path("")
    public async getAllTerms(): Promise {
        return this.termsController.getAvailableTerms();
    }

    @POST
    @Path("")
    @Security(ROLE_USER)
    public async signTerms(request: SignTermsRequest): Promise {
        await this.termsController.signTermsMatching(this.context.request.user, request.user_accepts);
        return {};
    }
}
github turt2live / matrix-dimension / src / api / admin / AdminTermsService.ts View on Github external
@Path("all")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async getPolicies(): Promise {
        return this.termsController.getPoliciesForAdmin();
    }

    @GET
    @Path(":shortcode/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async getPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise {
        return this.termsController.getPolicyForAdmin(shortcode, version);
    }

    @POST
    @Path(":shortcode/draft")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async createDraftPolicy(@PathParam("shortcode") shortcode: string, request: CreatePolicyObject): Promise {
        return this.termsController.createDraftPolicy(request.name, shortcode, request.text, request.url);
    }

    @POST
    @Path(":shortcode/publish/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async publishDraftPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise {
        return this.termsController.publishPolicy(shortcode, version);
    }

    @PUT
    @Path(":shortcode/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async updatePolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string, request: CreatePolicyObject): Promise {
        return this.termsController.updatePolicy(request.name, shortcode, version, request.text, request.url);
github turt2live / matrix-dimension / src / api / admin / AdminTermsService.ts View on Github external
@AutoWired
export class AdminTermsService {

    @Inject
    private termsController: TermsController;

    @GET
    @Path("all")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async getPolicies(): Promise {
        return this.termsController.getPoliciesForAdmin();
    }

    @GET
    @Path(":shortcode/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async getPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise {
        return this.termsController.getPolicyForAdmin(shortcode, version);
    }

    @POST
    @Path(":shortcode/draft")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async createDraftPolicy(@PathParam("shortcode") shortcode: string, request: CreatePolicyObject): Promise {
        return this.termsController.createDraftPolicy(request.name, shortcode, request.text, request.url);
    }

    @POST
    @Path(":shortcode/publish/:version")
    @Security([ROLE_USER, ROLE_ADMIN])
    public async publishDraftPolicy(@PathParam("shortcode") shortcode: string, @PathParam("version") version: string): Promise {
        return this.termsController.publishPolicy(shortcode, version);