Skip to content

Commit

Permalink
[FEATURE] #4 SNS 로그인 구현 (#6)
Browse files Browse the repository at this point in the history
* [base] firebase 라이브러리 추가 및 적용

* [base] google-services.json 추가

* [base] gitignore 업데이트

* [chore] 구글 로그인 의존성 마이그레이션

* [chore] 인터넷 권한 추가

* [chore] 미사용 리소스 제거

* [chore] target api 수정

* [chore] credentials proguard 추가

* [chore] login 모듈 manifest 제거

* [chore] 미사용 리소스 제거

* [chore] theme 디자인 시스템 반영 및 로그인 화면 등록

* [feature] 구글 로그인 구현

* [chore] 미사용 리소스 제거 및 즁요 정보 은닉화

* [chore] 트레일링 콤마 추가

* [chore] properties.getProperty elvis 연산 추가

* [chore] properties.getProperty("web_client_id") null인 경우 추가

* [chore] google client id ktlint ci 조건 추가
  • Loading branch information
jiwon2724 authored Jul 2, 2024
1 parent f26be0f commit 42ea40d
Show file tree
Hide file tree
Showing 18 changed files with 111 additions and 223 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/ktlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ jobs:
distribution: 'temurin'
cache: gradle

- name: check google client id
env:
GOOGLE_CLIENT_ID: ${{secrets.GOOGLE_CLIENT_ID}}
run: |
echo web_client_id=\""$GOOGLE_CLIENT_ID"\" >> local.properties
- name: Run ktlint
run: ./gradlew ktlintCheck

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
/captures
.externalNativeBuild
.cxx
local.properties
app/google-services.json
6 changes: 6 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/build
/build
/local.properties
google-services.json
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)

implementation(project(":core:ui"))
implementation(project(":feature:login"))
}
Empty file added app/google-services.json
Empty file.
4 changes: 3 additions & 1 deletion 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:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -11,7 +13,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Pokit"
tools:targetApi="31">
tools:targetApi="34">
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
34 changes: 3 additions & 31 deletions app/src/main/java/pokitmons/pokit/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,16 @@ package pokitmons.pokit
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import pokitmons.pokit.ui.theme.PokitTheme
import pokitmons.pokit.core.ui.theme.PokitTheme
import pokitmons.pokit.login.LoginScreen

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
PokitTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting("Android")
}
LoginScreen()
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
PokitTheme {
Greeting("Android")
}
}
27 changes: 21 additions & 6 deletions feature/login/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import java.io.FileInputStream
import java.util.Properties

plugins {
alias(libs.plugins.com.android.application)
alias(libs.plugins.com.android.library)
alias(libs.plugins.org.jetbrains.kotlin.android)
}

val properties = Properties()
val localPropertiesFile = rootProject.file("local.properties")

if (localPropertiesFile.exists()) {
properties.load(FileInputStream(localPropertiesFile))
}

android {
namespace = "pokitmons.pokit.login"
compileSdk = 34

defaultConfig {
applicationId = "pokitmons.pokit.login"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

buildConfigField("String", "WEB_CLIENT_ID", properties.getProperty("web_client_id") ?: "web_client_id is empty")

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary = true
}
}

buildFeatures {
buildConfig = true
}

buildTypes {
release {
isMinifyEnabled = false
Expand Down Expand Up @@ -50,7 +62,6 @@ android {
}

dependencies {

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
Expand All @@ -66,4 +77,8 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)

implementation(libs.androidx.credentials)
implementation(libs.androidx.credentials.play.services.auth)
implementation(libs.googleid)
}
7 changes: 6 additions & 1 deletion feature/login/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@

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

-if class androidx.credentials.CredentialManager
-keep class androidx.credentials.playservices.** {
*;
}
20 changes: 0 additions & 20 deletions feature/login/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Pokit">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Pokit">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
49 changes: 49 additions & 0 deletions feature/login/src/main/java/pokitmons/pokit/login/LoginScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package pokitmons.pokit.login

import android.annotation.SuppressLint
import android.util.Log
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.credentials.CredentialManager
import androidx.credentials.GetCredentialRequest
import com.google.android.libraries.identity.googleid.GetGoogleIdOption
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
import kotlinx.coroutines.launch

@SuppressLint("CoroutineCreationDuringComposition")
@Composable
fun LoginScreen() {
// TODO 서버 api 개발완료 후 viewmodel 연동 및 아키텍처 구축

Text(text = "로그인 테스트 화면")
val coroutineScope = rememberCoroutineScope()

val context = LocalContext.current
val credentialManager = CredentialManager.create(context)

val googleIdOption: GetGoogleIdOption = GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setServerClientId(BuildConfig.WEB_CLIENT_ID)
.setAutoSelectEnabled(true)
.build()

val request: GetCredentialRequest = GetCredentialRequest.Builder()
.addCredentialOption(googleIdOption)
.build()

coroutineScope.launch {
try {
val result = credentialManager.getCredential(
request = request,
context = context
)
val googleIdTokenCredential = GoogleIdTokenCredential.createFrom(result.credential.data)
val googleIdToken = googleIdTokenCredential.idToken
Log.d("success: ", googleIdToken)
} catch (e: Exception) {
Log.d("failed : ", e.message.toString())
}
}
}
46 changes: 0 additions & 46 deletions feature/login/src/main/java/pokitmons/pokit/login/MainActivity.kt

This file was deleted.

This file was deleted.

Loading

0 comments on commit 42ea40d

Please sign in to comment.