Skip to content

Commit 4897b6a

Browse files
authored
Merge pull request #399 from Quickchive/feat/add-apple-login
feat: 애플 로그인 추가
2 parents af7adfb + 4266b96 commit 4897b6a

File tree

2 files changed

+22
-30
lines changed

2 files changed

+22
-30
lines changed

src/auth/oauth.v2.controller.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ export class OauthV2Controller {
6161
return this.oauthService.googleOauth(oauthRequest);
6262
}
6363

64-
// @ApiOperation({
65-
// summary: '애플 로그인',
66-
// description:
67-
// '애플 로그인 메서드. (회원가입이 안되어 있으면 회원가입 처리 후 로그인 처리)',
68-
// })
69-
// @Get('apple-login')
70-
// async appleLogin(
71-
// @Body() oauthRequest: OAuthLoginRequest,
72-
// ): Promise<LoginOutput> {
73-
// return this.oauthService.appleLogin(oauthRequest);
74-
// }
64+
@ApiOperation({
65+
summary: '애플 로그인',
66+
description:
67+
'애플 로그인 메서드. (회원가입이 안되어 있으면 회원가입 처리 후 로그인 처리)',
68+
})
69+
@Post('apple-login')
70+
async appleLogin(
71+
@Body() oauthRequest: OAuthLoginRequest,
72+
): Promise<LoginOutput> {
73+
return this.oauthService.appleLogin(oauthRequest);
74+
}
7575
}

src/auth/oauth.v2.service.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
BadRequestException,
33
Injectable,
4-
InternalServerErrorException,
54
UnauthorizedException,
65
} from '@nestjs/common';
76
import { LoginOutput } from './dtos/login.dto';
@@ -22,6 +21,10 @@ import { ConfigService } from '@nestjs/config';
2221

2322
@Injectable()
2423
export 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

Comments
 (0)