Skip to content
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

Feat/#13 카카오 로그인 기능 설정 #28

Merged
merged 4 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ dependencies {
implementation(libs.play.service.auth)
implementation(libs.dagger.hilt)
kapt(libs.dagger.hilt.compiler)

implementation(libs.kakao.login)
}

kapt {
Expand Down
10 changes: 9 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,12 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keep class com.kakao.sdk.**.model.* { <fields>; }
-keep class * extends com.google.gson.TypeAdapter

# https://github.com/square/okhttp/pull/6792
-dontwarn org.bouncycastle.jsse.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.**
14 changes: 14 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".OworiApplication"
android:allowBackup="true"
Expand All @@ -25,6 +27,18 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kakao.sdk.auth.AuthCodeHandlerActivity"
android:exported="true">
<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="kakao6c28960f69d4c7f00043b02d890dd6e0" />
</intent-filter>
</activity>
</application>

</manifest>
2 changes: 2 additions & 0 deletions app/src/main/java/com/owori/android/OworiApplication.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.owori.android

import android.app.Application
import com.kakao.sdk.common.KakaoSdk
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class OworiApplication: Application() {
override fun onCreate() {
super.onCreate()
KakaoSdk.init(this, "6c28960f69d4c7f00043b02d890dd6e0")
Copy link
Member

Choose a reason for hiding this comment

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

서버키 같은 상수들은 따로 strings.xml 이나 별도의 configuration.xml 로 관리하는게 좋을거 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

별도의 configuration.xml에서 관리할 수 있도록 하겠습니다!

}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/owori/android/auth/data/AuthProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.owori.android.auth.data

enum class AuthProvider(val value: String) {
KAKAO("KAKAO"), GOOGLE("GOOGLE")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.owori.android.auth.data

data class MemberRequest (
val token: String,
val authProvider: AuthProvider
)
Original file line number Diff line number Diff line change
@@ -1,23 +1,62 @@
package com.owori.android.auth.ui.viewmodel

import android.content.ContentValues.TAG
import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
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 com.owori.android.common.SingleLiveEvent
import com.owori.android.common.ui.viewmodel.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

@HiltViewModel
class LoginViewModel @Inject constructor() : BaseViewModel() {
class LoginViewModel @Inject constructor(@ApplicationContext private val context: Context) : BaseViewModel() {
Copy link
Member

Choose a reason for hiding this comment

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

context를 주입받지 않고 그냥 AndroidViewModel을 사용해도 될 거 같습니다.
혹은 해당 context가 필요한 로직들은 activity에서 관장하고, 그 이후의 비즈니스 로직만 viewmodel에서 관리해도 될것으로 보입니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 context 필요한 로직은 viewmodel에서 분리하겠습니다!

private val _callKakaoLogin: SingleLiveEvent<Unit> = SingleLiveEvent()
val callKakaoLogin: LiveData<Unit> = _callKakaoLogin
private val _callGoogleLogin: SingleLiveEvent<Unit> = SingleLiveEvent()
val callGoogleLogin: LiveData<Unit> = _callGoogleLogin
val userApiClient = UserApiClient()

fun onClickKakaoLogin() {
_callKakaoLogin.call()
val callback: (OAuthToken?, Throwable?) -> Unit = { token, error ->
if (error != null) {
Log.e(TAG, "카카오계정으로 로그인 실패", error)
} else if (token != null) {
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.accessToken}")
Log.i(TAG, "카카오계정으로 로그인 성공 ${token.refreshToken}")
_callKakaoLogin.call()
}
}


if (userApiClient.isKakaoTalkLoginAvailable(context)) {
userApiClient.loginWithKakaoTalk(context) { token, error ->
if (error != null) {
Log.e(TAG, "카카오톡으로 로그인 실패", error)

if (error is ClientError && error.reason == ClientErrorCause.Cancelled) {
return@loginWithKakaoTalk
}

userApiClient.loginWithKakaoAccount(context, callback = callback)
} else if (token != null) {
Log.i(TAG, "카카오톡으로 로그인 성공 ${token.accessToken}")
}
}
} else {
userApiClient.loginWithKakaoAccount(context, callback = callback)
}
}

fun onClickGoogleLogin() {
_callGoogleLogin.call()
}


}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ google-services = "4.3.15"
play-service-auth = "20.7.0"
dagger-hilt = "2.44"
hilt-compiler = "2.44"
kakao-login = "2.17.0"

[libraries]
core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" }
Expand Down Expand Up @@ -72,6 +73,7 @@ firebase-auth = { group = "com.google.firebase", name = "firebase-auth-ktx" }
play-service-auth = { group = "com.google.android.gms", name = "play-services-auth", version.ref = "play-service-auth" }
dagger-hilt = { group = "com.google.dagger", name = "hilt-android", version.ref = "dagger-hilt" }
dagger-hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt-compiler" }
kakao-login = { group = "com.kakao.sdk", name = "v2-user", version.ref = "kakao-login" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven(url = "https://devrepo.kakao.com/nexus/content/groups/public/")
}
}

Expand Down