Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(project(":feature:friend"))
implementation(project(":core:designsystem"))
implementation(project(":core:navigation"))
implementation(project(":core:di"))
implementation(project(":common:resource"))

implementation(libs.androidx.core.splash)
Expand Down
3 changes: 3 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=".MemorySealApplication"
android:allowBackup="true"
Expand All @@ -12,6 +14,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Splash"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MainActivity"
Expand Down
25 changes: 25 additions & 0 deletions core/di/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import java.util.Properties

plugins {
id("convention.android.library")
id("convention.android.hilt")
}

android {
namespace = "com.idiotfrogs.di"

buildFeatures {
buildConfig = true
}

defaultConfig {
buildConfigField("String", "BASE_URL", getLocalProperty("BASE_URL"))
}
}

dependencies {
implementation(project(":data"))
implementation(project(":core:network"))

implementation(libs.retrofit)
implementation(libs.okhttp.logging.interceptor)
implementation(libs.retrofit.kotlin.serialization)
implementation(libs.kotlinx.serialization.json)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
}

fun getLocalProperty(name: String): String {
val propertiesFile = rootProject.file("local.properties")
val properties = Properties()
properties.load(propertiesFile.inputStream())
return properties.getProperty(name)
}
47 changes: 47 additions & 0 deletions core/di/src/main/java/com/idiotfrogs/di/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.idiotfrogs.di

import com.idiotfrogs.network.AuthService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.HttpLoggingInterceptor.Level
import retrofit2.Retrofit
import retrofit2.converter.kotlinx.serialization.asConverterFactory
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun providesJson() = Json {}

@Provides
@Singleton
fun providesOkHttpClient() =
OkHttpClient.Builder()
.addInterceptor(HttpLoggingInterceptor().apply { level = Level.BODY })
.build()

@Provides
@Singleton
fun providesRetrofit(
json: Json,
okHttpClient: OkHttpClient
): Retrofit =
Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.client(okHttpClient)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.build()

@Provides
@Singleton
fun providesAuthService(retrofit: Retrofit): AuthService =
retrofit.create(AuthService::class.java)
}
17 changes: 17 additions & 0 deletions core/di/src/main/java/com/idiotfrogs/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.idiotfrogs.di

import com.idiotfrogs.data.datasource.auth.AuthDataSource
import com.idiotfrogs.data.datasource.auth.AuthDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
interface DataSourceModule {
@Binds
fun bindsAuthDataSource(
authDataSourceImpl: AuthDataSourceImpl
): AuthDataSource
}
3 changes: 3 additions & 0 deletions core/model/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
plugins {
id("convention.android.library")
alias(libs.plugins.kotlin.serialization)
}

android {
namespace = "com.idiotfrogs.model"
}

dependencies {
implementation(libs.kotlinx.serialization.json)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
testImplementation(libs.junit)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.idiotfrogs.model.auth

import kotlinx.serialization.Serializable

@Serializable
data class AuthTokenRequest(
val idToken: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.idiotfrogs.model.auth

import kotlinx.serialization.Serializable

@Serializable
data class AuthTokenResponse(
val accessToken: String,
val refreshToken: String,
)
4 changes: 4 additions & 0 deletions core/network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ android {
}

dependencies {
implementation(project(":core:model"))

implementation(libs.retrofit)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
testImplementation(libs.junit)
Expand Down
11 changes: 11 additions & 0 deletions core/network/src/main/java/com/idiotfrogs/network/AuthService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.idiotfrogs.network

import com.idiotfrogs.model.auth.AuthTokenRequest
import com.idiotfrogs.model.auth.AuthTokenResponse
import retrofit2.http.Body
import retrofit2.http.POST

interface AuthService {
@POST("auth/login/google")
suspend fun socialGoogleLogin(@Body body: AuthTokenRequest): AuthTokenResponse
}
1 change: 1 addition & 0 deletions core/social-login/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
46 changes: 46 additions & 0 deletions core/social-login/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.util.Properties

plugins {
id("convention.android.library")
id("convention.android.hilt")
}

android {
namespace = "com.skogkatt.social_login"

buildFeatures {
buildConfig = true
}

defaultConfig {
buildConfigField("String", "WEB_CLIENT_ID", getLocalProperty("WEB_CLIENT_ID"))
}
}

dependencies {
implementation(project(":data"))
implementation(project(":core:model"))
implementation(project(":common:extension"))

// ๊ตฌ๊ธ€ ๋กœ๊ทธ์ธ
implementation(libs.androidx.credentials)
implementation(libs.androidx.credentials.play.service)
implementation(libs.identity.google.id)

// ์• ํ”Œ ๋กœ๊ทธ์ธ
implementation(platform(libs.firebase.bom))
implementation(libs.firebase.auth)

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext)
androidTestImplementation(libs.androidx.test.espresso)
}

fun getLocalProperty(name: String): String {
val propertiesFile = rootProject.file("local.properties")
val properties = Properties()
properties.load(propertiesFile.inputStream())
return properties.getProperty(name)
}
21 changes: 21 additions & 0 deletions core/social-login/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.skogkatt.social_login

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.skogkatt.social_login.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/social-login/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.idiotfrogs.data.remote
package com.skogkatt.social_login

import android.content.Context
import androidx.credentials.CredentialManager
Expand All @@ -11,9 +11,10 @@ import com.google.firebase.auth.AuthResult
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.auth.FirebaseAuthWebException
import com.google.firebase.auth.OAuthProvider
import com.idiotfrogs.data.BuildConfig
import com.idiotfrogs.data.datasource.auth.AuthDataSource
import com.idiotfrogs.data.exception.LoginCancelledException
import com.idiotfrogs.extension.findActivity
import com.idiotfrogs.model.auth.AuthTokenRequest
import dagger.hilt.android.qualifiers.ActivityContext
import dagger.hilt.android.scopes.ActivityScoped
import kotlinx.coroutines.suspendCancellableCoroutine
Expand All @@ -24,7 +25,8 @@ import kotlin.coroutines.resumeWithException
@ActivityScoped
class LoginManager @Inject constructor(
// ํ•„์š”ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ? (ex. ๋‚ด๋ถ€์ €์žฅ์†Œ ๋กœ์ง)
@ActivityContext private val context: Context
@ActivityContext private val context: Context,
private val authDataSource: AuthDataSource
) {
suspend fun googleLogin() {
val credentialManager = CredentialManager.create(context)
Expand All @@ -48,8 +50,11 @@ class LoginManager @Inject constructor(
?: throw Exception("Unexpected type of credential")

val googleIdTokenCredential = GoogleIdTokenCredential.createFrom(credential.data)
// TODO: idToken ๊ด€๋ จ ์ฒ˜๋ฆฌ
} catch (exception: GetCredentialCancellationException) {

val tokenResponse = authDataSource.socialGoogleLogin(
AuthTokenRequest(googleIdTokenCredential.idToken)
)
} catch (_: GetCredentialCancellationException) {
throw LoginCancelledException()
} catch (exception: Exception) {
throw exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.skogkatt.social_login

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
Loading