-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d4d0b8
commit 5e32f88
Showing
13 changed files
with
134 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsEmail, IsNotEmpty, IsPhoneNumber, IsString } from 'class-validator'; | ||
import { IsEmail, IsNotEmpty, IsString } from 'class-validator'; | ||
|
||
export class SignRequest { | ||
@ApiProperty({ description: '휴대폰 번호', example: '01012341234' }) | ||
@ApiProperty({ description: '이메일 주소', example: '[email protected]' }) | ||
@IsNotEmpty() | ||
@IsPhoneNumber('KR') | ||
phone: string; | ||
@IsEmail() | ||
email: string; | ||
|
||
@ApiProperty({ description: '패스워드' }) | ||
@IsNotEmpty() | ||
@IsString() | ||
password: string; | ||
} | ||
|
||
export class GoogleSignRequest extends SignRequest{ | ||
@IsNotEmpty() | ||
@IsEmail() | ||
mail : string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { HttpService } from "@nestjs/axios"; | ||
import { Injectable, UnauthorizedException } from "@nestjs/common"; | ||
import { ConfigService } from "@nestjs/config"; | ||
import { verify } from 'jsonwebtoken' | ||
import { firstValueFrom } from "rxjs"; | ||
@Injectable() | ||
export class GoogleService { | ||
|
||
private GOOGLE_OAUTH_URL = 'https://oauth2.googleapis.com/token' | ||
private GOOGLE_CLIENT_ID : string; | ||
private GOOGLE_CLIENT_SECRET : string; | ||
private GOOGLE_CALLBACK_URL : string; | ||
|
||
constructor( | ||
private readonly http : HttpService, | ||
private readonly config: ConfigService | ||
) { | ||
this.GOOGLE_CLIENT_ID = config.get<string>('GOOGLE_CLIENT_ID'); | ||
this.GOOGLE_CLIENT_SECRET = config.get<string>('GOOGLE_CLIENT_SECRET') | ||
this.GOOGLE_CALLBACK_URL = config.get<string>('GOOGLE_CALLBACK_URL') | ||
} | ||
|
||
/** | ||
* 구글 OAuth 로 authCode 를 보내 idToken 획득 후 email 추출 | ||
* @param code | ||
* @returns | ||
*/ | ||
async getEmailFromCode(code: string) : Promise<string> { | ||
if(!code) throw new UnauthorizedException('AuhorizationCode required') | ||
const { data } = await firstValueFrom(this.http.post<{ | ||
id_token : string, | ||
}>(this.GOOGLE_OAUTH_URL,{ | ||
code, | ||
client_id : this.GOOGLE_CLIENT_ID, | ||
client_secret : this.GOOGLE_CLIENT_SECRET, | ||
redirect_uri : this.GOOGLE_CALLBACK_URL, | ||
grant_type : 'authorization_code' | ||
})) | ||
const { id_token : idToken } = data; | ||
const decoded = verify(idToken, '', { complete: true }) as { | ||
payload: { email?: string }; | ||
}; | ||
const email = decoded?.payload?.email; | ||
if (!email) { | ||
throw new Error('Email not found in id_token'); | ||
} | ||
return email; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.