chore: add sso service and logic

This commit is contained in:
mahyargdz
2025-04-21 10:41:43 +03:30
parent 41b0652c47
commit 160040a4b7
16 changed files with 619 additions and 9 deletions
+34 -2
View File
@@ -7,18 +7,24 @@ import { CompleteRegistrationDto } from "./DTO/complete-register.dto";
import { CheckUserExistDto, LoginPasswordDTO } from "./DTO/loginPassword.dto";
import { RefreshTokenDto } from "./DTO/refresh-token.dto";
import { RequestOtpDto } from "./DTO/request-otp.dto";
import { SSOTokenRequestDTO } from "./DTO/requests/sso-token-request.dto";
import { VerifyOtpDto } from "./DTO/verify-otp.dto";
import { AuthService } from "./providers/auth.service";
import { SSOService } from "./providers/sso.service";
import { AUTH_THROTTLE_LIMIT, AUTH_THROTTLE_TTL, AUTH__REFRESH_THROTTLE_LIMIT, AUTH__REFRESH_THROTTLE_TTL } from "../../common/constants";
import { SSOTokenValidateDTO } from "./DTO/requests/sso-token-validate.dto";
import { AuthGuards } from "../../common/decorators/auth-guard.decorator";
import { UserDec } from "../../common/decorators/user.decorator";
import { User } from "../users/entities/user.entity";
@ApiTags("Auth")
@Controller("auth")
@Throttle({ default: { limit: AUTH_THROTTLE_LIMIT, ttl: AUTH_THROTTLE_TTL } })
@UseGuards(ThrottlerGuard)
export class AuthController {
constructor(private authService: AuthService) {}
constructor(
private readonly authService: AuthService,
private readonly ssoService: SSOService,
) {}
@ApiOperation({ summary: "Initiate registration" })
@HttpCode(HttpStatus.OK)
@@ -110,4 +116,30 @@ export class AuthController {
// async resetPassword(@Body() resetPasswordDto: ResetPasswordDto) {
// return this.authService.resetPassword(resetPasswordDto);
// }
@ApiOperation({ summary: "Generate SSO token for client application" })
@HttpCode(HttpStatus.OK)
@Post("/sso/token")
async generateSSOToken(@UserDec() user: User, @Body() body: SSOTokenRequestDTO) {
const { clientId } = body;
const ssoToken = await this.ssoService.generateSSOToken(user, clientId);
return {
statusCode: HttpStatus.OK,
data: ssoToken,
message: "SSO token generated successfully",
};
}
@ApiOperation({ summary: "Validate SSO token" })
@HttpCode(HttpStatus.OK)
@Post("/sso/validate")
async validateSSOToken(@Body() body: SSOTokenValidateDTO) {
const { token, clientId } = body;
const payload = await this.ssoService.validateSSOToken(token, clientId);
return {
statusCode: HttpStatus.OK,
data: payload,
message: "SSO token validated successfully",
};
}
}