-
Notifications
You must be signed in to change notification settings - Fork 3
[Refactor] 소셜로그인, 회원가입 관련 오류 수정 #128
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
Changes from all commits
bec459d
366a66c
31cbf2f
4cd2380
50cad19
10e338a
aafc413
992ffb3
e12595e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,9 +108,11 @@ dependencies { | |
| //implementation ("androidx.datastore:datastore-preferences:1.1.1") | ||
|
|
||
| // 구글 로그인 | ||
| implementation(platform("com.google.firebase:firebase-bom:34.1.0")) | ||
| implementation("com.google.firebase:firebase-auth") | ||
| implementation("com.google.android.gms:play-services-auth:21.2.0") | ||
|
|
||
| implementation("androidx.credentials:credentials:1.2.2") | ||
| implementation("androidx.credentials:credentials-play-services-auth:1.2.2") | ||
|
|
||
|
Comment on lines
+113
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainAndroidX Credentials 도입 OK. google-services 플러그인 제거 필요(중요)
다음으로 확인/정리하세요:
참고: Credentials(1.2.2) 추가는 적절하며 🏁 Script executed: #!/bin/bash
rg -n --glob '*gradle*' -S 'com.google.gms.google-services|firebase' || trueLength of output: 222
Credentials(1.2.2) 추가는 정상이며, play-services-auth 병행 사용 가능합니다. |
||
| } | ||
|
|
||
| kapt { | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| package com.texthip.thip.data.repository | ||
|
|
||
| import android.content.Context | ||
| import com.google.firebase.Firebase | ||
| import com.google.firebase.auth.GoogleAuthProvider | ||
| import com.google.firebase.auth.auth | ||
| import com.kakao.sdk.user.UserApiClient | ||
| import com.texthip.thip.data.model.auth.request.AuthRequest | ||
| import com.texthip.thip.data.model.auth.response.AuthResponse | ||
| import com.texthip.thip.data.model.base.handleBaseResponse | ||
| import com.texthip.thip.data.service.AuthService | ||
| import kotlinx.coroutines.CancellableContinuation | ||
| import kotlinx.coroutines.suspendCancellableCoroutine | ||
| import kotlinx.coroutines.tasks.await | ||
| import kotlinx.serialization.json.Json | ||
| import kotlinx.serialization.json.jsonObject | ||
| import kotlinx.serialization.json.jsonPrimitive | ||
| import java.util.Base64 | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
| import kotlin.coroutines.resume | ||
|
|
@@ -36,13 +36,14 @@ class AuthRepository @Inject constructor( | |
| } | ||
| suspend fun loginWithGoogle(idToken: String): Result<AuthResponse?> { | ||
| return runCatching { | ||
| //Firebase에 구글 ID 토큰으로 로그인 | ||
| val credential = GoogleAuthProvider.getCredential(idToken, null) | ||
| val authResult = Firebase.auth.signInWithCredential(credential).await() | ||
| val googleUid = authResult.user?.uid ?: throw IllegalStateException("Google User UID is null") | ||
| val payload = idToken.split('.')[1]//ID 토큰을 .기준 분리 | ||
| val decodedJson = String(Base64.getUrlDecoder().decode(payload))//디코딩 해서 JSON 문자열 반환 | ||
|
|
||
| val jsonObject = Json.parseToJsonElement(decodedJson).jsonObject | ||
| val googleSubId = jsonObject["sub"]?.jsonPrimitive?.content ?: throw IllegalStateException("구글 userID (sub)값이 없습니다.")//sub 값 추출 | ||
|
|
||
|
Comment on lines
+39
to
44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion JWT 페이로드 파싱 안전성 부족: 형식 검증·Base64URL 패딩·문자셋 누락으로 크래시 위험
아래처럼 형식 검증, - val payload = idToken.split('.')[1]//ID 토큰을 .기준 분리
- val decodedJson = String(Base64.getUrlDecoder().decode(payload))//디코딩 해서 JSON 문자열 반환
-
- val jsonObject = Json.parseToJsonElement(decodedJson).jsonObject
- val googleSubId = jsonObject["sub"]?.jsonPrimitive?.content ?: throw IllegalStateException("구글 userID (sub)값이 없습니다.")//sub 값 추출
+ val parts = idToken.split('.')
+ require(parts.size == 3) { "유효하지 않은 ID 토큰 형식입니다." }
+ val payloadB64 = parts[1]
+ val payloadBytes = android.util.Base64.decode(
+ payloadB64,
+ android.util.Base64.URL_SAFE or android.util.Base64.NO_PADDING or android.util.Base64.NO_WRAP
+ )
+ val decodedJson = payloadBytes.toString(Charsets.UTF_8)
+
+ val jsonObject = Json { ignoreUnknownKeys = true }
+ .parseToJsonElement(decodedJson).jsonObject
+ val googleSubId = jsonObject["sub"]?.jsonPrimitive?.content
+ ?: error("구글 userID(sub) 클레임이 없습니다.")🤖 Prompt for AI Agents |
||
| //받아온 UID로 신규/기존 유저인지 확인 요청 | ||
| val request = AuthRequest(oauth2Id = "google_$googleUid") | ||
| val request = AuthRequest(oauth2Id = "google_$googleSubId") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain서버 측 ID 토큰 검증(aud/iss/exp/서명) 보장 여부 확인 필요 클라이언트에서 서버가 검증하지 않는다면, 여기서 🏁 Script executed: #!/bin/bash
# idToken(혹은 Google 토큰) 서버 전송 및 검증 유무 탐색
rg -n -C3 '\bidToken\b|GoogleIdToken|Authorization: Bearer|checkNewUser\('Length of output: 5292 ID 토큰 원문 전달 및 서버 측 검증 보장 |
||
| authService.checkNewUser(request) | ||
| .handleBaseResponse() | ||
| .getOrThrow() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -114,7 +114,7 @@ fun EditProfileContent( | |
| WarningTextField( | ||
| containerColor = colors.DarkGrey02, | ||
| value = uiState.nickname, | ||
| onValueChange = onNicknameChange, | ||
| onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase()) }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 로케일 비의존 소문자 변환 사용
- onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase()) },
+ onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase(java.util.Locale.ROOT)) },추가(파일 상단 import): import java.util.Locale🤖 Prompt for AI Agents |
||
| hint = stringResource(R.string.nickname_condition), | ||
| showWarning = uiState.nicknameWarningMessageResId != null, | ||
| showIcon = false, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,7 +100,7 @@ fun SignupNicknameContent( | |
| WarningTextField( | ||
| containerColor = colors.DarkGrey02, | ||
| value = nickname, | ||
| onValueChange = onNicknameChange, | ||
| onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase()) },//소문자로 즉시 변경 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 로케일 비의존 소문자 변환 사용 동일 이유로 - onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase()) },//소문자로 즉시 변경
+ onValueChange = { newNickname -> onNicknameChange(newNickname.lowercase(java.util.Locale.ROOT)) }, // 소문자로 즉시 변경(로케일 비의존)추가(파일 상단 import): import java.util.Locale🤖 Prompt for AI Agents |
||
| hint = stringResource(R.string.nickname_condition), | ||
| showWarning = warningMessageResId != null, | ||
| showIcon = false, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
google-services.json 무시 추가는 적절. 단, google-services 플러그인이 남아 있으면 빌드 실패 가능성 있음
현재
app/build.gradle.kts의plugins블록에id("com.google.gms.google-services")가 남아 있습니다. Firebase 설정을 제거했다면 플러그인도 제거하세요. 파일이 없을 때 플러그인이 적용되면 빌드가 중단될 수 있습니다.다음 스크립트로 플러그인 잔존 여부와 파일 유무를 확인하세요.
🏁 Script executed:
Length of output: 619
플러그인 선언 제거 필요
.gitignore에google-services.json무시 처리는 적절하나,root
build.gradle.kts(7행)와app/build.gradle.kts(9행)에 남아 있는id("com.google.gms.google-services")선언을 삭제하세요.🤖 Prompt for AI Agents