Skip to content

Commit 216cf4a

Browse files
authored
Merge pull request #310 from Team-Clody/feat/#292-google-auth
[FEAT/#292] 구글 로그인 구현합니다.
2 parents a78740f + 8f766ef commit 216cf4a

28 files changed

+367
-99
lines changed

app/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ android {
3131
val amplitudeApiKey: String = properties.getProperty("amplitude.api.key")
3232
val googleAdmobAppId: String = properties.getProperty("GOOGLE_ADMOB_APP_ID", "")
3333
val googleAdmobUnitId: String = properties.getProperty("GOOGLE_ADMOB_UNIT_ID", "")
34+
val googleAuthWebClientId: String = properties.getProperty("GOOGLE_AUTH_WEB_CLIENT_ID", "")
3435
val allowedDomains: String = properties.getProperty("allowed.webview.domains", "notion.so,google.com")
3536

3637
buildConfigField("String", "GOOGLE_ADMOB_APP_ID", "\"$googleAdmobAppId\"")
3738
buildConfigField("String", "GOOGLE_ADMOB_UNIT_ID", "\"$googleAdmobUnitId\"")
3839
buildConfigField("String", "KAKAO_API_KEY", "\"$kakaoApiKey\"")
3940
buildConfigField("String", "AMPLITUDE_API_KEY", "\"$amplitudeApiKey\"")
41+
buildConfigField("String", "GOOGLE_AUTH_WEB_CLIENT_ID", "\"$googleAuthWebClientId\"")
4042
buildConfigField("String", "ALLOWED_WEBVIEW_DOMAINS", "\"$allowedDomains\"")
4143
manifestPlaceholders["kakaoRedirectUri"] = "kakao$kakaoApiKey"
4244
manifestPlaceholders["GOOGLE_ADMOB_APP_ID"] = googleAdmobAppId
@@ -153,4 +155,8 @@ dependencies {
153155
implementation(libs.coil)
154156
implementation(libs.kakao.user)
155157
implementation(libs.kotlinx.datetime)
158+
159+
implementation(libs.androidx.credentials.play.services.auth)
160+
implementation(libs.google.auth)
161+
implementation(libs.androidx.datastore.preferences)
156162
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.sopt.clody.data.datastore
2+
3+
import android.content.Context
4+
import dagger.Module
5+
import dagger.Provides
6+
import dagger.hilt.InstallIn
7+
import dagger.hilt.android.qualifiers.ApplicationContext
8+
import dagger.hilt.components.SingletonComponent
9+
import javax.inject.Singleton
10+
11+
@Module
12+
@InstallIn(SingletonComponent::class)
13+
object DataStoreModule {
14+
15+
@Provides
16+
@Singleton
17+
fun provideOAuthDataStore(
18+
@ApplicationContext context: Context,
19+
): OAuthDataStore {
20+
return OAuthDataStore(context)
21+
}
22+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.sopt.clody.data.datastore
2+
3+
import android.content.Context
4+
import androidx.datastore.preferences.core.edit
5+
import androidx.datastore.preferences.preferencesDataStore
6+
import dagger.hilt.android.qualifiers.ApplicationContext
7+
import kotlinx.coroutines.flow.first
8+
import javax.inject.Inject
9+
10+
class OAuthDataStore @Inject constructor(@ApplicationContext context: Context) {
11+
private val Context.dataStore by preferencesDataStore(name = "oauth_pref")
12+
private val dataStore = context.dataStore
13+
14+
suspend fun saveIdToken(token: String) {
15+
dataStore.edit { it[OAuthDataStoreKeys.GOOGLE_ID_TOKEN] = token }
16+
}
17+
18+
suspend fun getIdToken(): String? {
19+
return dataStore.data.first()[OAuthDataStoreKeys.GOOGLE_ID_TOKEN]
20+
}
21+
22+
suspend fun savePlatform(provider: OAuthProvider) {
23+
dataStore.edit { it[OAuthDataStoreKeys.OAUTH_PLATFORM] = provider.name }
24+
}
25+
26+
suspend fun getPlatform(): OAuthProvider? {
27+
return dataStore.data.first()[OAuthDataStoreKeys.OAUTH_PLATFORM]?.let {
28+
runCatching { OAuthProvider.valueOf(it) }.getOrNull()
29+
}
30+
}
31+
32+
suspend fun clear() {
33+
dataStore.edit {
34+
it.remove(OAuthDataStoreKeys.GOOGLE_ID_TOKEN)
35+
it.remove(OAuthDataStoreKeys.OAUTH_PLATFORM)
36+
}
37+
}
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.sopt.clody.data.datastore
2+
3+
import androidx.datastore.preferences.core.stringPreferencesKey
4+
5+
object OAuthDataStoreKeys {
6+
val GOOGLE_ID_TOKEN = stringPreferencesKey("google_id_token")
7+
val OAUTH_PLATFORM = stringPreferencesKey("oauth_platform")
8+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.sopt.clody.data.datastore
2+
3+
enum class OAuthProvider(val apiValue: String) {
4+
GOOGLE("google"),
5+
KAKAO("kakao"),
6+
}

app/src/main/java/com/sopt/clody/data/remote/api/AuthService.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sopt.clody.data.remote.api
22

33
import com.sopt.clody.data.remote.dto.base.ApiResponse
4+
import com.sopt.clody.data.remote.dto.request.GoogleSignUpRequestDto
45
import com.sopt.clody.data.remote.dto.request.LoginRequestDto
56
import com.sopt.clody.data.remote.dto.request.SignUpRequestDto
67
import com.sopt.clody.data.remote.dto.response.LoginResponseDto
@@ -21,4 +22,9 @@ interface AuthService {
2122
@Header("Authorization") authorization: String,
2223
@Body signUpRequestDto: SignUpRequestDto,
2324
): ApiResponse<SignUpResponseDto>
25+
26+
@POST("api/v1/auth/oauth2/google")
27+
suspend fun signUpWithGoogle(
28+
@Body body: GoogleSignUpRequestDto,
29+
): ApiResponse<SignUpResponseDto>
2430
}

app/src/main/java/com/sopt/clody/data/remote/datasource/AuthDataSource.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sopt.clody.data.remote.datasource
22

33
import com.sopt.clody.data.remote.dto.base.ApiResponse
4+
import com.sopt.clody.data.remote.dto.request.GoogleSignUpRequestDto
45
import com.sopt.clody.data.remote.dto.request.LoginRequestDto
56
import com.sopt.clody.data.remote.dto.request.SignUpRequestDto
67
import com.sopt.clody.data.remote.dto.response.LoginResponseDto
@@ -9,4 +10,5 @@ import com.sopt.clody.data.remote.dto.response.SignUpResponseDto
910
interface AuthDataSource {
1011
suspend fun signIn(authorization: String, requestSignInDto: LoginRequestDto): ApiResponse<LoginResponseDto>
1112
suspend fun signUp(authorization: String, requestSignUpDto: SignUpRequestDto): ApiResponse<SignUpResponseDto>
13+
suspend fun signUpWithGoogle(googleSignUpRequestDto: GoogleSignUpRequestDto): ApiResponse<SignUpResponseDto>
1214
}

app/src/main/java/com/sopt/clody/data/remote/datasourceimpl/AuthDataSourceImpl.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.sopt.clody.data.remote.datasourceimpl
33
import com.sopt.clody.data.remote.api.AuthService
44
import com.sopt.clody.data.remote.datasource.AuthDataSource
55
import com.sopt.clody.data.remote.dto.base.ApiResponse
6+
import com.sopt.clody.data.remote.dto.request.GoogleSignUpRequestDto
67
import com.sopt.clody.data.remote.dto.request.LoginRequestDto
78
import com.sopt.clody.data.remote.dto.request.SignUpRequestDto
89
import com.sopt.clody.data.remote.dto.response.LoginResponseDto
@@ -17,4 +18,7 @@ class AuthDataSourceImpl @Inject constructor(
1718

1819
override suspend fun signUp(authorization: String, requestSignUpDto: SignUpRequestDto): ApiResponse<SignUpResponseDto> =
1920
authService.signUp(authorization, requestSignUpDto)
21+
22+
override suspend fun signUpWithGoogle(googleSignUpRequestDto: GoogleSignUpRequestDto): ApiResponse<SignUpResponseDto> =
23+
authService.signUpWithGoogle(googleSignUpRequestDto)
2024
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.sopt.clody.data.remote.dto.request
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
data class GoogleSignUpRequestDto(
8+
@SerialName("idToken") val idToken: String,
9+
@SerialName("fcmToken") val fcmToken: String,
10+
)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.sopt.clody.data.remote.dto.response
22

3+
import com.sopt.clody.data.datastore.OAuthProvider
34
import kotlinx.serialization.SerialName
45
import kotlinx.serialization.Serializable
56

67
@Serializable
78
data class UserInfoResponseDto(
89
@SerialName("email") val email: String,
910
@SerialName("name") val name: String,
10-
@SerialName("platform") val platform: String,
11+
@SerialName("platform") val platform: OAuthProvider?,
1112
)

0 commit comments

Comments
 (0)