diff --git a/frontend/ARchive/app/build.gradle b/frontend/ARchive/app/build.gradle index 5457dfd27..c69047604 100644 --- a/frontend/ARchive/app/build.gradle +++ b/frontend/ARchive/app/build.gradle @@ -23,6 +23,7 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField "String", "KAKAO_NATIVE_APP_KEY", properties['kakao_native_app_key'] + buildConfigField "String", "GOOGLE_LOGIN_CLIENT_ID", properties['google_login_client_id'] manifestPlaceholders["KAKAO_NATIVE_APP_KEY"] = properties.getProperty("kakao_native_app_key_no_quotes") @@ -116,8 +117,11 @@ dependencies { implementation 'com.google.android.gms:play-services-auth:20.7.0' implementation 'com.google.android.gms:play-services-auth-api-phone:18.0.1' - // KaKao + // KaKao Login implementation "com.kakao.sdk:v2-user:2.12.1" + + // Goole Login + implementation 'com.google.android.gms:play-services-auth:20.7.0' } kapt { correctErrorTypes true diff --git a/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/auth/SignInFragment.kt b/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/auth/SignInFragment.kt index b1528c9ea..92c24ef40 100644 --- a/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/auth/SignInFragment.kt +++ b/frontend/ARchive/app/src/main/java/com/droidblossom/archive/presentation/ui/auth/SignInFragment.kt @@ -3,16 +3,25 @@ package com.droidblossom.archive.presentation.ui.auth import android.os.Bundle import android.util.Log import android.view.View +import androidx.activity.result.contract.ActivityResultContracts import androidx.fragment.app.activityViewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import androidx.navigation.NavController import androidx.navigation.Navigation +import com.droidblossom.archive.BuildConfig import com.droidblossom.archive.R import com.droidblossom.archive.databinding.FragmentSignInBinding import com.droidblossom.archive.presentation.base.BaseFragment import com.droidblossom.archive.presentation.ui.MainActivity +import com.google.android.gms.auth.api.signin.GoogleSignIn +import com.google.android.gms.auth.api.signin.GoogleSignInAccount +import com.google.android.gms.auth.api.signin.GoogleSignInClient +import com.google.android.gms.auth.api.signin.GoogleSignInOptions +import com.google.android.gms.common.api.ApiException +import com.google.android.gms.common.api.Scope +import com.google.android.gms.tasks.Task import com.kakao.sdk.auth.model.OAuthToken import com.kakao.sdk.common.model.ClientError import com.kakao.sdk.common.model.ClientErrorCause @@ -34,21 +43,41 @@ class SignInFragment : BaseFragment(R.l if (error != null) { Log.e("카카오", "로그인 실패 $error") } else if (token != null) { - Log.e("카카오", "로그인 성공 ${token.accessToken}") + Log.e("카카오2", "로그인 성공 ${token.accessToken}") } } + private var googleLoginLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == -1) { + val data = result.data + val task = GoogleSignIn.getSignedInAccountFromIntent(data) + getGoogleInfo(task) + } + } + + private val googleSignInClient: GoogleSignInClient by lazy { + GoogleSignIn.getClient(requireContext(), googleSignInOptions) + } + + private val googleSignInOptions: GoogleSignInOptions by lazy { + GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestEmail() + .build() + } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) navController = Navigation.findNavController(view) + binding.kakaoLoginBtn.setOnClickListener { - kakaoLogin() + //viewModel.signInToSignUp() + kakaoSignIn() } binding.googleLoginBtn.setOnClickListener { - viewModel.signInToSignUp() + //viewModel.signInToSignUp() + googleSignIn() } } @@ -78,10 +107,8 @@ class SignInFragment : BaseFragment(R.l } } - private fun kakaoLogin(){ - // 카카오톡 설치 확인 + private fun kakaoSignIn(){ if (UserApiClient.instance.isKakaoTalkLoginAvailable(requireContext())) { - // 카카오톡 로그인 UserApiClient.instance.loginWithKakaoTalk(requireContext()) { token, error -> // 로그인 실패 부분 if (error != null) { @@ -99,11 +126,30 @@ class SignInFragment : BaseFragment(R.l // 로그인 성공 부분 else if (token != null) { viewModel.SignInSuccess() - Log.e("카카오", "로그인 성공 ${token.accessToken}") + Log.e("카카오1", "로그인 성공 ${token.accessToken}") } } } else { UserApiClient.instance.loginWithKakaoAccount(requireContext(), callback = mCallback) // 카카오 이메일 로그인 } } + + private fun googleSignIn() { + val signInIntent = googleSignInClient.signInIntent + googleLoginLauncher.launch(signInIntent) + } + private fun getGoogleInfo(completedTask: Task) { + try { + val TAG = "구글 로그인 결과" + val account = completedTask.getResult(ApiException::class.java) + Log.d(TAG, account.id!!) + Log.d(TAG, account.familyName!!) + Log.d(TAG, account.givenName!!) + Log.d(TAG, account.email!!) + } + catch (e: ApiException) { + Log.w("구글", "signInResult:failed code=" + e.statusCode) + } + } + } \ No newline at end of file