Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

소셜 Id토큰 검증 충돌 해결 #251

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions server/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ import axios from 'axios';
import { InvalidKakaoIdTokenException } from 'src/exceptions/invalid-kakao-idtoken.exception';
import { InconsistentKakaoUuidException } from 'src/exceptions/inconsistent-kakao-uuid.exception';
import { createPublicKey } from 'crypto';
import { PlatformEnum, SignupRequestDto } from './dto/signup-request.dto';
import { OAuth2Client } from 'google-auth-library';
import { InvalidGoogldIdTokenException } from 'src/exceptions/invalid-google-idToken.exception';
import { InconsistentGoogldUuidException } from 'src/exceptions/inconsistent-google-uuid.exception';
import { SignupRequestDto } from './dto/signup-request.dto';
import { PlatformEnum, SignupRequestDto } from './dto/signup-request.dto';
import { JwtDto } from './dto/jwt.dto';
import { SignupResponseDto } from './dto/signup-response.dto';
import { SigninResponseDto } from './dto/signin-response.dto';
Expand Down Expand Up @@ -148,6 +147,10 @@ export class AuthService {

async verifyUuid(platform: PlatformEnum, idToken: string, uuid: string) {
switch (platform) {
case PlatformEnum.GOOGLE:
if (uuid !== (await this.verifyGoogleIdToken(idToken)))
throw new InconsistentGoogldUuidException();
break;
case PlatformEnum.KAKAO:
if (uuid !== (await this.verifyKakaoIdToken(idToken)))
throw new InconsistentKakaoUuidException();
Expand All @@ -168,16 +171,6 @@ export class AuthService {
);
}

async verifyUuid(platform: string, idToken: string, uuid: string) {
switch (platform) {
case 'GOOGLE':
if (uuid !== (await this.verifyGoogleIdToken(idToken)))
throw new InconsistentGoogldUuidException();
break;
default:
}
}

async verifyGoogleIdToken(idToken: string) {
const client = new OAuth2Client();

Expand All @@ -197,12 +190,4 @@ export class AuthService {
throw new InvalidGoogldIdTokenException();
}
}

formatAsUUID(mostSigBits, leastSigBits) {
const most = mostSigBits.toString('16').padStart(16, '0');
const least = leastSigBits.toString('16').padStart(16, '0');
return `${most.substring(0, 8)}-${most.substring(8, 12)}-${most.substring(
12,
)}-${least.substring(0, 4)}-${least.substring(4)}`;
}
}