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: {