-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
227 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
core/network/src/main/java/com/easyhz/noffice/core/network/api/auth/AuthService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.easyhz.noffice.core.network.api.auth | ||
|
||
import com.easyhz.noffice.core.network.model.request.sign.LoginRequest | ||
import com.easyhz.noffice.core.network.model.response.auth.UserResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("/api/v1/member/login") | ||
suspend fun login( | ||
@Body body: LoginRequest | ||
): Result<UserResponse> | ||
} |
17 changes: 17 additions & 0 deletions
17
core/network/src/main/java/com/easyhz/noffice/core/network/di/service/AuthModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.easyhz.noffice.core.network.di.service | ||
|
||
import com.easyhz.noffice.core.network.api.auth.AuthService | ||
import com.easyhz.noffice.core.network.di.NofficeRetrofit | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import retrofit2.Retrofit | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AuthModule { | ||
@Provides | ||
fun provideAuthService(@NofficeRetrofit retrofit: Retrofit): AuthService = | ||
retrofit.create(AuthService::class.java) | ||
} |
6 changes: 6 additions & 0 deletions
6
.../network/src/main/java/com/easyhz/noffice/core/network/model/request/sign/LoginRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.easyhz.noffice.core.network.model.request.sign | ||
|
||
data class LoginRequest( | ||
val code: String, | ||
val provider: String | ||
) |
6 changes: 6 additions & 0 deletions
6
...etwork/src/main/java/com/easyhz/noffice/core/network/model/response/auth/TokenResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.easyhz.noffice.core.network.model.response.auth | ||
|
||
data class TokenResponse( | ||
val accessToken: String, | ||
val refreshToken: String | ||
) |
8 changes: 8 additions & 0 deletions
8
...network/src/main/java/com/easyhz/noffice/core/network/model/response/auth/UserResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.easyhz.noffice.core.network.model.response.auth | ||
|
||
data class UserResponse( | ||
val memberId: String, | ||
val memberName: String, | ||
val provider: String, | ||
val token: TokenResponse | ||
) |
18 changes: 18 additions & 0 deletions
18
data/auth/src/main/java/com/easyhz/noffice/data/auth/di/repository/AuthRepositoryModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.easyhz.noffice.data.auth.di.repository | ||
|
||
import com.easyhz.noffice.data.auth.repository.login.LoginRepository | ||
import com.easyhz.noffice.data.auth.repository.login.LoginRepositoryIml | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
interface AuthRepositoryModule { | ||
|
||
@Binds | ||
fun bindAuthRepository( | ||
loginRepositoryIml: LoginRepositoryIml | ||
): LoginRepository | ||
} |
20 changes: 20 additions & 0 deletions
20
data/auth/src/main/java/com/easyhz/noffice/data/auth/di/strategy/LoginStrategyModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.easyhz.noffice.data.auth.di.strategy | ||
|
||
import com.easyhz.noffice.data.auth.strategy.BaseStrategy | ||
import com.easyhz.noffice.data.auth.strategy.GoogleStrategy | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class LoginStrategyModule { | ||
|
||
@Binds | ||
@Singleton | ||
abstract fun bindGoogleStrategy( | ||
googleStrategy: GoogleStrategy | ||
): BaseStrategy | ||
} |
7 changes: 7 additions & 0 deletions
7
data/auth/src/main/java/com/easyhz/noffice/data/auth/repository/login/LoginRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.easyhz.noffice.data.auth.repository.login | ||
|
||
import android.content.Context | ||
|
||
interface LoginRepository { | ||
suspend fun loginWithGoogle(context: Context): Result<Unit> | ||
} |
23 changes: 23 additions & 0 deletions
23
data/auth/src/main/java/com/easyhz/noffice/data/auth/repository/login/LoginRepositoryIml.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.easyhz.noffice.data.auth.repository.login | ||
|
||
import android.content.Context | ||
import com.easyhz.noffice.core.network.api.auth.AuthService | ||
import com.easyhz.noffice.core.network.model.request.sign.LoginRequest | ||
import com.easyhz.noffice.data.auth.strategy.GoogleStrategy | ||
import com.easyhz.noffice.data.auth.util.Provider | ||
import javax.inject.Inject | ||
|
||
class LoginRepositoryIml @Inject constructor( | ||
private val googleStrategy: GoogleStrategy, | ||
private val authService: AuthService | ||
): LoginRepository { | ||
override suspend fun loginWithGoogle(context: Context): Result<Unit> = runCatching { | ||
val authorizationCode = googleStrategy.login(context).getOrThrow() | ||
val request = LoginRequest( | ||
code = authorizationCode, | ||
provider = Provider.GOOGLE.name | ||
) | ||
|
||
val a = authService.login(request).getOrThrow() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
data/auth/src/main/java/com/easyhz/noffice/data/auth/strategy/BaseStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.easyhz.noffice.data.auth.strategy | ||
|
||
import android.content.Context | ||
|
||
interface BaseStrategy { | ||
|
||
suspend fun login(context: Context): Result<String> | ||
|
||
suspend fun logout() | ||
} |
64 changes: 64 additions & 0 deletions
64
data/auth/src/main/java/com/easyhz/noffice/data/auth/strategy/GoogleStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.easyhz.noffice.data.auth.strategy | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.credentials.CredentialManager | ||
import androidx.credentials.CustomCredential | ||
import androidx.credentials.GetCredentialRequest | ||
import androidx.credentials.GetCredentialResponse | ||
import com.easyhz.noffice.core.common.error.NofficeError | ||
import com.easyhz.noffice.data.auth.BuildConfig | ||
import com.google.android.libraries.identity.googleid.GetGoogleIdOption | ||
import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential | ||
import com.google.android.libraries.identity.googleid.GoogleIdTokenParsingException | ||
import javax.inject.Inject | ||
|
||
class GoogleStrategy @Inject constructor( | ||
): BaseStrategy { | ||
private val tag = this.javaClass.name | ||
|
||
override suspend fun login(context: Context): Result<String> = runCatching { | ||
val googleIdOption: GetGoogleIdOption = GetGoogleIdOption.Builder() | ||
.setServerClientId(BuildConfig.GOOGLE_CLIENT_ID) | ||
.setFilterByAuthorizedAccounts(false) | ||
.setAutoSelectEnabled(false) | ||
.build() | ||
|
||
val request: GetCredentialRequest = | ||
GetCredentialRequest.Builder().addCredentialOption( | ||
googleIdOption | ||
).build() | ||
|
||
val result = | ||
CredentialManager.create(context) | ||
.getCredential(context = context, request = request) | ||
handleGoogleSignIn(result) | ||
} | ||
|
||
override suspend fun logout() { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
private fun handleGoogleSignIn(result: GetCredentialResponse): String { | ||
when (val credential = result.credential) { | ||
is CustomCredential -> { | ||
if (credential.type == GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL) { | ||
try { | ||
val googleIdTokenCredential = GoogleIdTokenCredential | ||
.createFrom(credential.data) | ||
return googleIdTokenCredential.idToken | ||
} catch (e: GoogleIdTokenParsingException) { | ||
throw e | ||
} | ||
} else { | ||
Log.d(tag, "Unexpected type of credential (not TYPE_GOOGLE_ID_TOKEN_CREDENTIAL). ") | ||
throw NofficeError.UnexpectedError | ||
} | ||
} | ||
else -> { | ||
Log.d(tag, "Unexpected type of credential (not custom).") | ||
throw NofficeError.UnexpectedError | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
data/auth/src/main/java/com/easyhz/noffice/data/auth/util/Provider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.easyhz.noffice.data.auth.util | ||
|
||
enum class Provider { | ||
} |
13 changes: 13 additions & 0 deletions
13
domain/sign/src/main/java/com/easyhz/noffice/domain/sign/usecase/LoginUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.easyhz.noffice.domain.sign.usecase | ||
|
||
import android.content.Context | ||
import com.easyhz.noffice.core.common.base.BaseUseCase | ||
import com.easyhz.noffice.data.auth.repository.login.LoginRepository | ||
import javax.inject.Inject | ||
|
||
class LoginUseCase @Inject constructor( | ||
private val loginRepository: LoginRepository | ||
): BaseUseCase<Context, Unit>() { | ||
override suspend fun invoke(param: Context): Result<Unit> = | ||
loginRepository.loginWithGoogle(param) | ||
} |
3 changes: 2 additions & 1 deletion
3
feature/sign/src/main/java/com/easyhz/noffice/feature/sign/contract/login/LoginIntent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package com.easyhz.noffice.feature.sign.contract.login | ||
|
||
import android.content.Context | ||
import com.easyhz.noffice.core.common.base.UiIntent | ||
|
||
sealed class LoginIntent : UiIntent() { | ||
data object ClickToLogInWithGoogle: LoginIntent() | ||
data class ClickToLogInWithGoogle(val context: Context): LoginIntent() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters