feat: add telegram authorization
This commit is contained in:
parent
13e4937925
commit
98643fee39
@ -6,7 +6,8 @@ import {
|
||||
HttpStatus,
|
||||
Post,
|
||||
Req,
|
||||
Res, UnauthorizedException
|
||||
Res,
|
||||
UnauthorizedException
|
||||
} from '@nestjs/common'
|
||||
import { ConfigService } from '@nestjs/config'
|
||||
import { ApiOperation } from '@nestjs/swagger'
|
||||
@ -16,6 +17,7 @@ import { lastValueFrom } from 'rxjs'
|
||||
import { AuthClientGrpc } from './auth.grpc'
|
||||
import {
|
||||
SendOtpRequestDto,
|
||||
TelegramFinalyzeRequestDto,
|
||||
TelegramVerifyDto,
|
||||
VerifyOtpRequestDto
|
||||
} from './dto'
|
||||
@ -137,4 +139,27 @@ export class AuthController {
|
||||
|
||||
throw new UnauthorizedException('Invalid telegram login response')
|
||||
}
|
||||
|
||||
@Post('telegram/finalize')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
public async finalyzeTelegramLogin(
|
||||
@Body() dto: TelegramFinalyzeRequestDto,
|
||||
@Res({ passthrough: true }) res: Response
|
||||
) {
|
||||
const { sessionId } = dto
|
||||
|
||||
const { accessToken, refreshToken } = await lastValueFrom(
|
||||
this.client.telegramConsume({ sessionId })
|
||||
)
|
||||
|
||||
res.cookie('refreshToken', refreshToken, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === 'production',
|
||||
domain: this.config.getOrThrow('COOKIES_DOMAIN'),
|
||||
sameSite: 'lax',
|
||||
maxAge: 30 * 24 * 60 * 60 * 1000
|
||||
})
|
||||
|
||||
return { accessToken }
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
AuthServiceClient,
|
||||
RefreshRequest,
|
||||
SendOtpRequest,
|
||||
TelegramConsumeRequest,
|
||||
TelegramVerifyRequest,
|
||||
VerifyOtpRequest
|
||||
} from '@teacinema/contracts/gen/auth'
|
||||
@ -37,4 +38,8 @@ export class AuthClientGrpc implements OnModuleInit {
|
||||
public telegramVerify(request: TelegramVerifyRequest) {
|
||||
return this.authService.telegramVerify(request)
|
||||
}
|
||||
|
||||
public telegramConsume(request: TelegramConsumeRequest) {
|
||||
return this.authService.telegramConsume(request)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
export * from './send-otp.request.dto'
|
||||
export * from './verify-otp.request.dto'
|
||||
export * from './telegram-verify.dto'
|
||||
export * from './telegram-finalyze.request.dto'
|
||||
|
||||
12
src/modules/auth/dto/rq/telegram-finalyze.request.dto.ts
Normal file
12
src/modules/auth/dto/rq/telegram-finalyze.request.dto.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { ApiProperty } from '@nestjs/swagger'
|
||||
import { IsNotEmpty, IsString } from 'class-validator'
|
||||
|
||||
export class TelegramFinalyzeRequestDto {
|
||||
@ApiProperty({
|
||||
description: 'Telegram session id',
|
||||
example: '4399b5e099fb40a8e6e8a4ca5120e43c'
|
||||
})
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
sessionId: string
|
||||
}
|
||||
@ -1221,9 +1221,9 @@
|
||||
integrity sha512-q3DURJbSk3k8MNWFIYaSM4LEcBgPbWa+HJmBz/nzYT4kuYitJVSXxpZ97kr0Ea+81AZwAU3JhQKlkK0SBWUi0A==
|
||||
|
||||
"@teacinema/contracts@^1.0.0":
|
||||
version "1.0.8"
|
||||
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.0.8/contracts-1.0.8.tgz#4e31c3a370b0808629d9c93900c5f27958ef82e6"
|
||||
integrity sha512-xyPyifbVwWelgo4MsvhhRl//To+b0Tnp8DtANCzwLBUhwPj3ZG19QgfPB7Ih7PsBU5TD6F80aNlITDxJbFgkFQ==
|
||||
version "1.0.9"
|
||||
resolved "https://git.ksv741.keenetic.pro/api/packages/teacinema/npm/%40teacinema%2Fcontracts/-/1.0.9/contracts-1.0.9.tgz#14b136d0c08552147b0de637a7af6d340d538527"
|
||||
integrity sha512-9BwWvXaDKgRcef6+1ep9vUDWBdOndqheeTX5mXK5OOvLXbLOlzYoqAUoT0ZwaRwOCD+Je/LDrqcdti6eoss71Q==
|
||||
dependencies:
|
||||
"@nestjs/microservices" "^11.1.12"
|
||||
protoc "33.4.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user