mirror of
https://github.com/PeterMaquiran/tvone-api.git
synced 2026-04-22 12:05:50 +00:00
auth to category
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
"@prisma/client": "^7.7.0",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.2",
|
||||
"cookie-parser": "^1.4.7",
|
||||
"jwks-rsa": "^4.0.1",
|
||||
"minio": "^8.0.6",
|
||||
"passport": "^0.7.0",
|
||||
|
||||
Generated
+7581
File diff suppressed because it is too large
Load Diff
@@ -2,6 +2,7 @@ import { ValidationPipe } from '@nestjs/common';
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
||||
import { AppModule } from './app.module';
|
||||
import cookieParser from "cookie-parser";
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
@@ -19,6 +20,8 @@ async function bootstrap() {
|
||||
credentials: true,
|
||||
});
|
||||
|
||||
app.use(cookieParser());
|
||||
|
||||
const config = new DocumentBuilder()
|
||||
.setTitle('Cats example')
|
||||
.setDescription('The cats API description')
|
||||
|
||||
@@ -2,12 +2,16 @@ import { Injectable } from "@nestjs/common";
|
||||
import { PassportStrategy } from "@nestjs/passport";
|
||||
import { ExtractJwt, Strategy } from "passport-jwt";
|
||||
import * as jwksRsa from "jwks-rsa";
|
||||
import { Request } from "express";
|
||||
|
||||
@Injectable()
|
||||
export class KeycloakStrategy extends PassportStrategy(Strategy, "keycloak") {
|
||||
constructor() {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
jwtFromRequest: ExtractJwt.fromExtractors([
|
||||
(req: Request) => req?.cookies?.access_token || null,
|
||||
ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
]),
|
||||
|
||||
// 🔑 Get signing key from Keycloak
|
||||
secretOrKeyProvider: jwksRsa.passportJwtSecret({
|
||||
|
||||
@@ -22,31 +22,33 @@ import { UpdateCategoryDto } from './dto/update-category.dto';
|
||||
export class CategoriesController {
|
||||
constructor(private readonly categoriesService: CategoriesService) {}
|
||||
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@Get()
|
||||
tree() {
|
||||
return this.categoriesService.tree();
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@Get('flat')
|
||||
flat() {
|
||||
return this.categoriesService.findAllFlat();
|
||||
}
|
||||
|
||||
//@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
//@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
@Post()
|
||||
create(@Body() dto: CreateCategoryDto) {
|
||||
return this.categoriesService.create(dto);
|
||||
}
|
||||
|
||||
//@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
//@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
@Patch(':id')
|
||||
update(@Param('id', ParseUUIDPipe) id: string, @Body() dto: UpdateCategoryDto) {
|
||||
return this.categoriesService.update(id, dto);
|
||||
}
|
||||
|
||||
//@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
@UseGuards(AuthGuard('keycloak'), UserProvisioningGuard, RolesGuard)
|
||||
//@Roles(UserRole.ADMIN, UserRole.EDITOR)
|
||||
@Delete(':id')
|
||||
remove(@Param('id', ParseUUIDPipe) id: string) {
|
||||
|
||||
Reference in New Issue
Block a user