11import {
22 BadRequestException ,
33 Injectable ,
4- InternalServerErrorException ,
54 UnauthorizedException ,
65} from '@nestjs/common' ;
76import { LoginOutput } from './dtos/login.dto' ;
@@ -22,6 +21,10 @@ import { ConfigService } from '@nestjs/config';
2221
2322@Injectable ( )
2423export class OAuthV2Service {
24+ private readonly googleClient = new OAuth2Client (
25+ this . configService . get ( 'GOOGLE_SECRET' ) ,
26+ ) ;
27+
2528 constructor (
2629 private readonly jwtService : customJwtService ,
2730 private readonly userRepository : UserRepository ,
@@ -31,10 +34,6 @@ export class OAuthV2Service {
3134 private readonly configService : ConfigService ,
3235 ) { }
3336
34- private readonly googleClient = new OAuth2Client (
35- this . configService . get ( 'GOOGLE_SECRET' ) ,
36- ) ;
37-
3837 // OAuth Login
3938 async oauthLogin ( email : string , provider : PROVIDER ) : Promise < LoginOutput > {
4039 try {
@@ -111,6 +110,7 @@ export class OAuthV2Service {
111110 }
112111
113112 // Login with Google account info
113+ // @todo 액세스 토큰 파싱하는 부분 추상화
114114 async googleOauth ( {
115115 authorizationToken,
116116 } : OAuthLoginRequest ) : Promise < LoginOutput > {
@@ -150,20 +150,8 @@ export class OAuthV2Service {
150150 return this . oauthLogin ( newUser . email , PROVIDER . GOOGLE ) ;
151151 }
152152
153- private encodePasswordFromEmail ( email : string , key ?: string ) : string {
154- return CryptoJS . SHA256 ( email + key ) . toString ( ) ;
155- }
156-
157- public async appleLogin ( code : string ) {
158- const data = await this . oauthUtil . getAppleToken ( code ) ;
159-
160- if ( ! data . id_token ) {
161- throw new InternalServerErrorException (
162- `No token: ${ JSON . stringify ( data ) } ` ,
163- ) ;
164- }
165-
166- const { sub : id , email } = this . jwtService . decode ( data . id_token ) ;
153+ public async appleLogin ( { authorizationToken } : OAuthLoginRequest ) {
154+ const { sub : id , email } = this . jwtService . decode ( authorizationToken ) ;
167155
168156 const user = await this . userRepository . findOneByEmailAndProvider (
169157 email ,
@@ -189,4 +177,8 @@ export class OAuthV2Service {
189177
190178 return this . oauthLogin ( newUser . email , PROVIDER . APPLE ) ;
191179 }
180+
181+ private encodePasswordFromEmail ( email : string , key ?: string ) : string {
182+ return CryptoJS . SHA256 ( email + key ) . toString ( ) ;
183+ }
192184}
0 commit comments