Skip to content

Commit

Permalink
feat : Apple Login
Browse files Browse the repository at this point in the history
Firebase Authentication을 사용하여 Apple Login 사용
현재는 Apple Developer에 등록한 Service ID 등록 대기중
  • Loading branch information
dogdduddy committed Mar 7, 2023
1 parent 64a3724 commit 7a04a86
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 5 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,11 @@ jobs:
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build

- name: Build debug APK
run: ./gradlew assembleDebug
- name: Upload APK
uses: actions/upload-artifact@v1
with:
name: app
path: app/build/outputs/apk/debug
18 changes: 17 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.gms.google-services'
}

android {
Expand All @@ -16,7 +17,14 @@ android {

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
storeFile file("../../jmtKey.jks")
storePassword "$System.env.KEYSTORE_PASSWORD"
keyAlias "$System.env.KEY_ALIAS"
keyPassword "$System.env.KEY_PASSWORD"
}
}
buildTypes {
release {
minifyEnabled false
Expand Down Expand Up @@ -57,6 +65,14 @@ dependencies {
// Gson 변환기
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

// firebase
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation platform('com.google.firebase:firebase-bom:31.2.0')

// Add the dependency for the Firebase Authentication library
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-auth-ktx'

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
Expand Down
47 changes: 47 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"project_info": {
"project_number": "846233671186",
"project_id": "matzip-jmt",
"storage_bucket": "matzip-jmt.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:846233671186:android:0ca9a58252f491a5da6acb",
"android_client_info": {
"package_name": "com.dogdduddy.jmt"
}
},
"oauth_client": [
{
"client_id": "846233671186-v1mirmbuqar5n0djl73cefot811vutne.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.dogdduddy.jmt",
"certificate_hash": "3f1cc906a92375c5e73f09bd409b3ceb499cbaef"
}
},
{
"client_id": "846233671186-4vknaa3i38pfkeourp2q37lolncdbmhl.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDr0G-cb7iz9fgJ15eON842Akv4DxstLRk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "846233671186-4vknaa3i38pfkeourp2q37lolncdbmhl.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
2 changes: 0 additions & 2 deletions app/src/main/java/com/dogdduddy/jmt/network/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class App:Application() {
super.onCreate()
appContext = this
instance = this


}

override fun onTerminate() {
Expand Down
47 changes: 46 additions & 1 deletion app/src/main/java/com/dogdduddy/jmt/view/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.ApiException
import com.google.android.gms.tasks.Task
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.OAuthProvider
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
Expand All @@ -36,6 +38,49 @@ class LoginActivity : AppCompatActivity() {
binding = ActivityLoginBinding.inflate(layoutInflater)
setContentView(binding.root)

/// 애플 로그인

binding.appleLoginBtn.setOnClickListener {
Log.d(TAG, "appleLoginBtn Clicked")
val provider = OAuthProvider.newBuilder("apple.com")
// provider.setScopes(mutableListOf("email", "name"))

val auth = FirebaseAuth.getInstance()

val pending = auth.pendingAuthResult
if (pending != null) {
Log.d(TAG, "peding : not null")
pending.addOnSuccessListener { authResult ->
Log.d(TAG, "checkPending:onSuccess:$authResult")
// Get the user profile with authResult.getUser() and
// authResult.getAdditionalUserInfo(), and the ID
// token from Apple with authResult.getCredential().
authResult.user?.getIdToken(true)?.addOnSuccessListener {
Log.d(TAG, "checkPending:onSuccess:$it")
}
Log.d("TAG", "checkAuth/UserInfo : ${authResult.additionalUserInfo}")
Log.d("TAG", "checkAuth/credential : ${authResult.credential}")
}.addOnFailureListener { e ->
Log.w(TAG, "checkPending:onFailure", e)
}
} else {
Log.d(TAG, "pending: null")
}

// 대기 중 결과가 없다면 실행
auth.startActivityForSignInWithProvider(this, provider.build())
.addOnSuccessListener { authResult ->
// Sign-in successful!
Log.d(TAG, "activitySignIn:onSuccess:${authResult.user}")
val user = authResult.user
// ...
}
.addOnFailureListener { e ->
Log.w(TAG, "activitySignIn:onFailure", e)
}
}

///

binding.googleLoginBtn.setOnClickListener {
lifecycleScope.launch(CoroutineExceptionHandler { _, throwable -> throwable.printStackTrace() }) {
Expand All @@ -55,7 +100,7 @@ class LoginActivity : AppCompatActivity() {
if (intent != null) {
val credential = loginViewModel.getCredential(intent)
val googleIdToken = credential.googleIdToken
Log.d(TAG, "Token : ${googleIdToken}")

loginViewModel.postToken(googleIdToken)
} else {
Log.d(TAG, "Google Login Failed")
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.LoginActivity">
<Button
android:id="@+id/appleLoginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="apple"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.gms.common.SignInButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ buildscript {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'

}
}
plugins {
id 'com.android.application' version '7.4.0' apply false
id 'com.android.library' version '7.4.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.21' apply false
}
}

0 comments on commit 7a04a86

Please sign in to comment.