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