-
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.
- Loading branch information
Showing
69 changed files
with
811 additions
and
147 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
18 changes: 18 additions & 0 deletions
18
data/network/src/main/java/co/kr/data/network/authenticator/Authenticator.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,18 @@ | ||
package co.kr.data.network.authenticator | ||
|
||
import co.kr.data.network.monitor.NetworkSessionMonitor | ||
import okhttp3.Authenticator | ||
import okhttp3.Request | ||
import okhttp3.Response | ||
import okhttp3.Route | ||
import javax.inject.Inject | ||
|
||
// 구현체 주입 여부 재검토 필요. | ||
internal class Authenticator @Inject constructor( | ||
private val networkSessionMonitor: NetworkSessionMonitor, | ||
) : Authenticator { | ||
override fun authenticate(route: Route?, response: Response): Request? { | ||
networkSessionMonitor.sendExpired() | ||
return null | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
data/network/src/main/java/co/kr/data/network/di/MonitorModule.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.di | ||
|
||
import co.kr.data.network.monitor.NetworkSessionMonitor | ||
import co.kr.tnt.domain.monitor.SessionMonitor | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class MonitorModule { | ||
@Binds | ||
abstract fun bindsSessionMonitor( | ||
monitor: NetworkSessionMonitor, | ||
): SessionMonitor | ||
} |
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
23 changes: 23 additions & 0 deletions
23
data/network/src/main/java/co/kr/data/network/interceptor/SessionInterceptor.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,23 @@ | ||
package co.kr.data.network.interceptor | ||
|
||
import co.kr.data.network.provider.SessionProvider | ||
import kotlinx.coroutines.runBlocking | ||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import javax.inject.Inject | ||
|
||
internal class SessionInterceptor @Inject constructor( | ||
private val sessionProvider: SessionProvider, | ||
) : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
val originRequest = chain.request() | ||
val requestBuilder = originRequest.newBuilder() | ||
|
||
requestBuilder.addHeader( | ||
"AUTHORIZATION", | ||
"SESSION-ID ${runBlocking { sessionProvider.getSessionId() }}", | ||
) | ||
|
||
return chain.proceed(requestBuilder.build()) | ||
} | ||
} |
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, | ||
) |
Oops, something went wrong.