-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from YAPP-Github/feature/TNT-103
[TNT-103] 로그인 구현
- Loading branch information
Showing
46 changed files
with
512 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
package co.kr.tnt | ||
|
||
import android.app.Application | ||
import com.kakao.sdk.common.KakaoSdk | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class TnTApplication : Application() | ||
class TnTApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
KakaoSdk.init(this, BuildConfig.KAKAO_NATIVE_APP_KEY) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import co.kr.tnt.setNamespace | ||
import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties | ||
|
||
plugins { | ||
id("tnt.android.library") | ||
} | ||
|
||
android { | ||
setNamespace("core.login") | ||
|
||
defaultConfig { | ||
manifestPlaceholders["KAKAO_NATIVE_APP_KEY"] = | ||
gradleLocalProperties(rootDir, providers).getProperty("KAKAO_NATIVE_APP_KEY") | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.kakao.user) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
<activity | ||
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity" | ||
android:exported="true" | ||
android:launchMode="singleTask"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.VIEW" /> | ||
<category android:name="android.intent.category.DEFAULT" /> | ||
<category android:name="android.intent.category.BROWSABLE" /> | ||
|
||
<data | ||
android:host="oauth" | ||
android:scheme="kakao${KAKAO_NATIVE_APP_KEY}" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package co.kr.tnt.login | ||
|
||
interface LoginAccessToken { | ||
val value: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package co.kr.tnt.login | ||
|
||
sealed class LoginException(override val message: String?) : Exception(message) { | ||
/** 유저가 뒤로가기 동작 등으로 로그인 자체를 취소한 경우 */ | ||
data class CancelException(override val message: String?) : LoginException(message) | ||
|
||
/** 유저가 실제 로그인을 시도하였으나 SDK의 문제로 로그인에 실패한 경우 */ | ||
data class AuthException(override val message: String?) : LoginException(message) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package co.kr.tnt.login | ||
|
||
import android.content.Context | ||
|
||
interface LoginSdk { | ||
suspend fun login(context: Context): Result<LoginAccessToken> | ||
suspend fun logout(): Result<Unit> | ||
suspend fun unlink(): Result<Unit> | ||
} |
6 changes: 6 additions & 0 deletions
6
core/login/src/main/java/co/kr/tnt/login/kakao/KakaoAccessToken.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package co.kr.tnt.login.kakao | ||
|
||
import co.kr.tnt.login.LoginAccessToken | ||
|
||
@JvmInline | ||
value class KakaoAccessToken(override val value: String) : LoginAccessToken |
78 changes: 78 additions & 0 deletions
78
core/login/src/main/java/co/kr/tnt/login/kakao/KakaoLoginSdk.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package co.kr.tnt.login.kakao | ||
|
||
import android.content.Context | ||
import co.kr.tnt.login.LoginAccessToken | ||
import co.kr.tnt.login.LoginException.AuthException | ||
import co.kr.tnt.login.LoginException.CancelException | ||
import co.kr.tnt.login.LoginSdk | ||
import com.kakao.sdk.auth.model.OAuthToken | ||
import com.kakao.sdk.common.model.ClientError | ||
import com.kakao.sdk.common.model.ClientErrorCause | ||
import com.kakao.sdk.user.UserApiClient | ||
import kotlinx.coroutines.suspendCancellableCoroutine | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.resumeWithException | ||
|
||
@Singleton | ||
class KakaoLoginSdk @Inject constructor() : LoginSdk { | ||
override suspend fun login(context: Context): Result<LoginAccessToken> = runCatching { | ||
suspendCancellableCoroutine { continuation -> | ||
val callback: (OAuthToken?, Throwable?) -> Unit = callback@{ token, throwable -> | ||
if (!continuation.isActive) { | ||
return@callback | ||
} | ||
|
||
when { | ||
throwable != null -> { | ||
if (throwable is ClientError && throwable.reason == ClientErrorCause.Cancelled) { | ||
continuation.resumeWithException(CancelException(throwable.message)) | ||
return@callback | ||
} | ||
|
||
continuation.resumeWithException(AuthException(throwable.message)) | ||
} | ||
|
||
token != null -> continuation.resume(KakaoAccessToken(token.accessToken)) | ||
} | ||
} | ||
|
||
val userApiClient = UserApiClient.instance | ||
|
||
if (userApiClient.isKakaoTalkLoginAvailable(context)) { | ||
// 카카오톡 로그인 | ||
userApiClient.loginWithKakaoTalk(context, callback = callback) | ||
} else { | ||
// 카카오톡 웹 로그인 | ||
userApiClient.loginWithKakaoAccount(context, callback = callback) | ||
} | ||
} | ||
} | ||
|
||
override suspend fun logout(): Result<Unit> = runCatching { | ||
suspendCancellableCoroutine { continuation -> | ||
val userApiClient = UserApiClient.instance | ||
|
||
userApiClient.logout { throwable -> | ||
when { | ||
throwable != null -> continuation.resumeWithException(AuthException(throwable.message)) | ||
else -> continuation.resume(Unit) | ||
} | ||
} | ||
} | ||
} | ||
|
||
override suspend fun unlink(): Result<Unit> = runCatching { | ||
suspendCancellableCoroutine { continuation -> | ||
val userApiClient = UserApiClient.instance | ||
|
||
userApiClient.unlink { throwable -> | ||
when { | ||
throwable != null -> continuation.resumeWithException(AuthException(throwable.message)) | ||
else -> continuation.resume(Unit) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
data/network/src/main/java/co/kr/data/network/model/LoginRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package co.kr.data.network.model | ||
|
||
import co.kr.tnt.domain.model.AuthType | ||
import kotlinx.serialization.Serializable | ||
|
||
// TODO fcm token | ||
@Serializable | ||
data class LoginRequest( | ||
val socialType: AuthType, | ||
val fcmToken: String = "EMPTY", | ||
val socialAccessToken: String, | ||
) |
25 changes: 25 additions & 0 deletions
25
data/network/src/main/java/co/kr/data/network/model/LoginResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package co.kr.data.network.model | ||
|
||
import co.kr.tnt.domain.model.AuthType | ||
import co.kr.tnt.domain.model.LoginResult | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* @property sessionId 세션 ID, 비회원인 경우 null | ||
*/ | ||
@Serializable | ||
data class LoginResponse( | ||
val sessionId: String?, | ||
val socialId: String, | ||
val socialEmail: String, | ||
val socialType: AuthType, | ||
val isSignUp: Boolean, | ||
) | ||
|
||
fun LoginResponse.toDomain(): LoginResult = | ||
LoginResult( | ||
authId = socialId, | ||
email = socialEmail, | ||
authType = socialType, | ||
isSignUp = isSignUp, | ||
) |
13 changes: 13 additions & 0 deletions
13
data/network/src/main/java/co/kr/data/network/service/ApiService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package co.kr.data.network.service | ||
|
||
import co.kr.data.network.model.LoginRequest | ||
import co.kr.data.network.model.LoginResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface ApiService { | ||
@POST("/login") | ||
suspend fun postLogin( | ||
@Body request: LoginRequest, | ||
): LoginResponse | ||
} |
3 changes: 0 additions & 3 deletions
3
data/network/src/main/java/co/kr/data/network/service/TnTService.kt
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
data/network/src/main/java/co/kr/data/network/source/LoginRemoteDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package co.kr.data.network.source | ||
|
||
import co.kr.data.network.model.LoginRequest | ||
import co.kr.data.network.model.LoginResponse | ||
import co.kr.data.network.service.ApiService | ||
import co.kr.data.network.util.networkHandler | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class LoginRemoteDataSource @Inject constructor( | ||
private val apiService: ApiService, | ||
) { | ||
suspend fun postLogin(loginRequest: LoginRequest): LoginResponse = networkHandler { | ||
apiService.postLogin(loginRequest) | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
data/network/src/main/java/co/kr/data/network/source/TnTDataSource.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
data/network/src/main/java/co/kr/data/network/tnt/request/TnTRequest.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
data/network/src/main/java/co/kr/data/network/tnt/response/TnTResponse.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.