Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 추가한 이유있을까요? 구글 로그인 만이면 굳이 핸드폰 자체의 계정까지 가져오지 않아도 되고 GoogleSignInClient으로 대체된 것으로 알아요

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 초기에 구글 로그인 연동 때, 오류 나서 이것 저것 시도했던 흔적이.. 남아 있네요. Client id 문제였던걸로 해결됐으니, 삭제하겠습니다!

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/paw/key/data/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.paw.key.data.di

import android.content.ContentResolver
import android.content.Context
import androidx.credentials.CredentialManager
import com.paw.key.BuildConfig
import dagger.Module
import dagger.Provides
Expand All @@ -26,4 +27,16 @@ object AppModule {
fun provideContentResolver(@ApplicationContext context: Context): ContentResolver {
return context.contentResolver
}

@Provides
@Singleton
fun provideContext(@ApplicationContext context: Context): Context {
return context
}

@Provides
@Singleton
fun provideCredentialManager(@ApplicationContext context: Context): CredentialManager {
return CredentialManager.create(context)
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/paw/key/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ object NetworkModule {
fun providesOkHttpClient(
loggingInterceptor: HttpLoggingInterceptor,
): OkHttpClient = OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addInterceptor(loggingInterceptor)
.build()

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/paw/key/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import com.paw.key.data.repositoryimpl.list.PostsListRepositoryImpl
import com.paw.key.data.repositoryimpl.login.AuthRepositoryImpl
import com.paw.key.data.repositoryimpl.walklist.WalkListDetailRepositoryImpl
import com.paw.key.data.repositoryimpl.walkreview.WalkReviewRepositoryImpl
import com.paw.key.data.remote.datasource.datasourceimpl.AuthRemoteDataSourceImpl
import com.paw.key.data.remote.datasource.datasourceimpl.GoogleAuthDataSourceImpl
import com.paw.key.data.remote.datasource.login.AuthRemoteDataSource
import com.paw.key.data.remote.datasource.login.GoogleAuthDataSource
import com.paw.key.domain.repository.ArchivedListRepository
import com.paw.key.domain.repository.DummyRepository
import com.paw.key.domain.repository.LikeRepository
Expand Down Expand Up @@ -50,6 +54,18 @@ import javax.inject.Singleton
@InstallIn(SingletonComponent::class)
interface RepositoryModule {

@Binds
@Singleton
fun bindAuthRemoteDataSource(
impl: AuthRemoteDataSourceImpl,
): AuthRemoteDataSource

@Binds
@Singleton
fun bindGoogleAuthDataSource(
impl: GoogleAuthDataSourceImpl,
): GoogleAuthDataSource

@Binds
fun bindsDummyRepository(
dummyRepositoryImpl: DummyRepositoryImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import kotlinx.serialization.Serializable

@Serializable
data class LoginRequestDto (
@SerialName("email")
val email: String,
@SerialName("idToken")
val idToken: String,
@SerialName("deviceId")
val deviceId: String
)
// 테스트용입니다


fun LoginRequestDto.toEntity(): LoginRequestDto {
val email = this.email
return LoginRequestDto(email)
val idToken = this.idToken
val deviceId = this.deviceId
return LoginRequestDto(idToken, deviceId)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import kotlinx.serialization.Serializable

@Serializable
data class LoginResponseDto (
@SerialName("AccessToken")
val AccessToken: String,
@SerialName("RefreshToken")
val RefreshToken: String
@SerialName("accessToken")
val accessToken: String,
@SerialName("refreshToken")
val refreshToken: String
)
// 테스트용입니다
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import com.paw.key.data.service.login.LoginService
import javax.inject.Inject

class AuthRemoteDataSourceImpl @Inject constructor(
private val loginService: LoginService,
private val loginService: LoginService
) : AuthRemoteDataSource {
override suspend fun login(
providerToken: String,
provider: String,
): BaseResponse<LoginResponseDto> =
loginService.login(providerToken, LoginRequestDto(provider))
}
override suspend fun login(idToken: String, deviceId: String): LoginResponseDto {
return loginService.login(
LoginRequestDto(
idToken = idToken,
deviceId = deviceId
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ import com.google.android.libraries.identity.googleid.GetGoogleIdOption
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
import com.paw.key.BuildConfig
import com.paw.key.core.util.suspendRunCatching
import com.paw.key.data.dto.request.LoginRequestDto
import com.paw.key.data.dto.response.BaseResponse
import com.paw.key.data.dto.response.LoginResponseDto
import com.paw.key.data.remote.datasource.login.AuthRemoteDataSource
import com.paw.key.data.remote.datasource.login.GoogleAuthDataSource
import com.paw.key.data.service.login.LoginService
import timber.log.Timber
import javax.inject.Inject

class GoogleAuthDataSourceImpl @Inject constructor(
Expand All @@ -22,7 +18,6 @@ class GoogleAuthDataSourceImpl @Inject constructor(
suspendRunCatching {
val googleIdOption = GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setAutoSelectEnabled(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 요거는 왜 지우셨을까요? 이유가 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것도 위와 같은 이유인데, 등록된 계정만 가능할 수 있게? 해준다해서 세팅하다가.. 다시 돌려놓겠습니다

.setServerClientId(BuildConfig.GOOGLE_WEB_CLIENT_ID)
.build()

Expand All @@ -32,5 +27,6 @@ class GoogleAuthDataSourceImpl @Inject constructor(

val response = credentialManager.getCredential(context, request)
GoogleIdTokenCredential.createFrom(response.credential.data)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.paw.key.data.dto.response.BaseResponse
import com.paw.key.data.dto.response.LoginResponseDto

interface AuthRemoteDataSource {
suspend fun login(providerToken: String, provider: String): BaseResponse<LoginResponseDto>
suspend fun login(idToken: String, deviceId: String): LoginResponseDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,33 @@ import com.paw.key.data.dto.response.LoginResponseDto
import com.paw.key.data.remote.datasource.login.AuthRemoteDataSource
import com.paw.key.data.remote.datasource.login.GoogleAuthDataSource
import com.paw.key.domain.repository.login.AuthRepository
import dagger.hilt.android.qualifiers.ApplicationContext
import timber.log.Timber
import javax.inject.Inject

class AuthRepositoryImpl @Inject constructor(
private val authRemoteDataSource: AuthRemoteDataSource,
private val googleAuthDataSource: GoogleAuthDataSource,
private val context: Context
@ApplicationContext private val context: Context
) : AuthRepository {

override suspend fun signInWithGoogle(context: Context): Result<String> =
googleAuthDataSource.signIn(context).map { it.idToken }

override suspend fun login(providerToken: String, provider: String): Result<LoginResponseDto> =
override suspend fun login(idToken: String, deviceId: String): Result<LoginResponseDto> =
suspendRunCatching {
val loginResponse = authRemoteDataSource.login(providerToken, provider).data

val loginResponse = authRemoteDataSource.login(idToken, deviceId)

UserDataStore.saveAcessToken(
context = context,
token = loginResponse.AccessToken
context = this.context,
token = loginResponse.accessToken
)
UserDataStore.saveRefreshToken(
context = context,
token = loginResponse.RefreshToken
context = this.context,
token = loginResponse.refreshToken
)

loginResponse
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import retrofit2.http.POST


interface LoginService {
@POST("api/v1/auth/login")
@POST("auth/google/login")
suspend fun login(
@Header("Authorization") providerToken: String,
@Body loginRequestDto: LoginRequestDto
): BaseResponse<LoginResponseDto>
): LoginResponseDto
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import com.paw.key.data.dto.response.LoginResponseDto

interface AuthRepository {
suspend fun signInWithGoogle(context: Context): Result<String>
suspend fun login(providerToken: String, provider: String): Result<LoginResponseDto>
suspend fun login(idToken: String, deviceId: String): Result<LoginResponseDto>
}
Loading