"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthController = void 0; const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const auth_service_1 = require("./auth.service"); let AuthController = class AuthController { authService; constructor(authService) { this.authService = authService; } async login(returnTo, res) { const redirect = await this.authService.createAuthorizationRedirect(returnTo); return res.redirect(302, redirect); } async callback(code, state, res) { const result = await this.authService.handleCallback(code, state); // set cookies const cookieOptions = { httpOnly: true, secure: process.env.NODE_ENV === 'production', sameSite: 'lax', path: '/', }; // access token cookie (internal JWT) res.cookie('raylab_jwt', result.accessToken, { ...cookieOptions, maxAge: result.expiresIn * 1000 }); // refresh token cookie res.cookie('raylab_refresh', result.refreshToken, { ...cookieOptions, maxAge: result.refreshTtl * 1000 }); return res.redirect(302, result.returnTo || '/'); } async logout(req, res) { const refreshToken = req.cookies?.raylab_refresh || req.body?.refreshToken; const redirect = await this.authService.logout(refreshToken); return res.redirect(302, redirect); } async refresh(req) { const refreshToken = req.cookies?.raylab_refresh || req.body?.refreshToken; const result = await this.authService.refresh(refreshToken); return { success: true, data: result }; } async me(req) { const token = (req.cookies?.raylab_jwt) || (req.headers.authorization && req.headers.authorization.replace(/^Bearer\s+/i, '')); const user = await this.authService.me(token); return { success: true, data: user }; } }; exports.AuthController = AuthController; __decorate([ (0, common_1.Get)('login'), (0, swagger_1.ApiOperation)({ summary: 'Start Authorization Code + PKCE login (redirect to Identity Provider)' }), __param(0, (0, common_1.Query)('returnTo')), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "login", null); __decorate([ (0, common_1.Get)('callback'), (0, swagger_1.ApiOperation)({ summary: 'OIDC callback endpoint' }), __param(0, (0, common_1.Query)('code')), __param(1, (0, common_1.Query)('state')), __param(2, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, String, Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "callback", null); __decorate([ (0, common_1.Post)('logout'), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: 'Logout (invalidate internal session and redirect to identity provider logout)' }), __param(0, (0, common_1.Req)()), __param(1, (0, common_1.Res)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "logout", null); __decorate([ (0, common_1.Post)('refresh'), (0, swagger_1.ApiOperation)({ summary: 'Refresh internal JWT using internal refresh token' }), __param(0, (0, common_1.Req)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "refresh", null); __decorate([ (0, common_1.Get)('me'), (0, swagger_1.ApiOperation)({ summary: 'Get current user from internal JWT (cookie or Authorization header)' }), __param(0, (0, common_1.Req)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], AuthController.prototype, "me", null); exports.AuthController = AuthController = __decorate([ (0, swagger_1.ApiTags)('Auth'), (0, common_1.Controller)('auth'), __metadata("design:paramtypes", [auth_service_1.AuthService]) ], AuthController); //# sourceMappingURL=auth.controller.js.map