From 74987f5484a759e5cec87f6830a43beadc008c6d Mon Sep 17 00:00:00 2001 From: miensoap Date: Sat, 9 Nov 2024 13:06:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B8=80=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20url=20API=EC=B6=94=EA=B0=80=20#81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/auth/auth.controller.ts | 7 ++++++- backend/src/auth/auth.service.ts | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/src/auth/auth.controller.ts b/backend/src/auth/auth.controller.ts index c152b990..12e0350a 100644 --- a/backend/src/auth/auth.controller.ts +++ b/backend/src/auth/auth.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Post } from '@nestjs/common'; +import { Body, Controller, Post, Get } from '@nestjs/common'; import { AuthService } from './auth.service'; import { UserService } from '../user/user.service'; import { CreateUserRequest } from '../user/dto/CreateUserRequest'; @@ -10,6 +10,11 @@ export class AuthController { private readonly userService: UserService, ) {} + @Get('google/signIn') + async googleSignIn() { + return this.authService.getGoogleAuthUrl(); + } + @Post('google/signIn') async googleCallback(@Body('code') code: string) { const tokens = await this.authService.getGoogleToken(code); diff --git a/backend/src/auth/auth.service.ts b/backend/src/auth/auth.service.ts index c24b3e5e..a2c37278 100644 --- a/backend/src/auth/auth.service.ts +++ b/backend/src/auth/auth.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import * as jwt from 'jsonwebtoken'; -import { googleTokenResponse, googleUserResponse } from './authType'; +import { googleTokenResponse, googleUserResponse } from './auth.type'; @Injectable() export class AuthService { @@ -19,9 +19,14 @@ export class AuthService { this.jwtExpiration = this.configService.get('JWT_EXPIRATION'); } - async getGoogleToken( - code: string, - ): Promise<{ accessToken: string; refreshToken: string }> { + getGoogleAuthUrl() { + const url = new URL('https://accounts.google.com/o/oauth2/v2/auth'); + url.searchParams.append('client_id', this.clientId); + url.searchParams.append('redirect_uri', this.redirectUri); + url.searchParams.append('response_type', 'code'); + url.searchParams.append('scope', 'openid profile'); + return url.toString(); + } return fetch('https://oauth2.googleapis.com/token', { method: 'POST', headers: {