From 27f9d5951fce3d73248b9798a36f94f3c045433c Mon Sep 17 00:00:00 2001 From: Hyun-Woo Lee <54518925+l2hyunwoo@users.noreply.github.com> Date: Mon, 17 Apr 2023 17:24:06 +0900 Subject: [PATCH] =?UTF-8?q?[feature/update-new-auth-host]=20APP=20?= =?UTF-8?q?=ED=8C=80=20=EC=84=9C=EB=B2=84=EC=97=90=EC=84=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=EB=90=9C=20=EB=B6=80=EB=B6=84=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?(#2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * API 업데이트 된 부분 수정 * Version bump to 0.1.3 --- README.md | 2 +- auth/build.gradle | 4 ++-- auth/src/main/AndroidManifest.xml | 6 +++--- .../org/sopt/official/playground/auth/Constants.kt | 1 + .../sopt/official/playground/auth/PlaygroundAuth.kt | 13 +++++++------ .../sopt/official/playground/auth/PlaygroundInfo.kt | 6 ++++-- .../playground/auth/data/PlaygroundApiManager.kt | 8 ++++---- .../auth/data/PlaygroundAuthDatasource.kt | 4 ++-- .../auth/data/RemotePlaygroundAuthDatasource.kt | 4 ++-- .../playground/auth/data/remote/AuthService.kt | 6 +++--- .../auth/data/remote/model/request/RequestToken.kt | 2 ++ .../auth/data/remote/model/response/OauthToken.kt | 10 ++++++---- .../playground/auth/utils/PlaygroundUriProvider.kt | 3 ++- build.gradle | 4 ++-- example/build.gradle | 2 +- example/src/main/AndroidManifest.xml | 1 + .../org/sopt/official/example/auth/MainActivity.kt | 8 ++++++-- 17 files changed, 49 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 6abe28e..fa7fd2e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Add in in your root build.gradle at the end of repositories: ** Step2. Add the dependency** ```groovy dependencies { - implementation 'com.github.sopt-makers:sopt-android-pgauth:0.1.2' + implementation 'com.github.sopt-makers:sopt-android-pgauth:0.1.3' } ``` diff --git a/auth/build.gradle b/auth/build.gradle index 305315d..4fd64c0 100644 --- a/auth/build.gradle +++ b/auth/build.gradle @@ -38,7 +38,7 @@ android { } dependencies { - implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.core:core-ktx:1.10.0' implementation 'androidx.appcompat:appcompat:1.6.1' implementation 'com.google.android.material:material:1.8.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' @@ -65,7 +65,7 @@ publishing { maven(MavenPublication) { groupId = 'com.github.sopt-makers' artifactId = 'auth' - version = '0.1.2' + version = '0.1.3' afterEvaluate { from components.release diff --git a/auth/src/main/AndroidManifest.xml b/auth/src/main/AndroidManifest.xml index 3b44b65..15f1e94 100644 --- a/auth/src/main/AndroidManifest.xml +++ b/auth/src/main/AndroidManifest.xml @@ -1,12 +1,12 @@ - + + android:theme="@style/TransparentTheme"> diff --git a/auth/src/main/java/org/sopt/official/playground/auth/Constants.kt b/auth/src/main/java/org/sopt/official/playground/auth/Constants.kt index 8df0dc7..3346bfd 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/Constants.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/Constants.kt @@ -1,6 +1,7 @@ package org.sopt.official.playground.auth internal object Constants { + val NOT_SECURE_SCHEME: String = "http" val SCHEME: String = "https" val REDIRECT_URI: String = "redirect_uri" val CODE: String = "code" diff --git a/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundAuth.kt b/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundAuth.kt index b1a1d37..3d1f4f0 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundAuth.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundAuth.kt @@ -9,7 +9,7 @@ import kotlinx.coroutines.launch import org.sopt.official.playground.auth.data.PlaygroundApiManager import org.sopt.official.playground.auth.data.PlaygroundAuthDatasource import org.sopt.official.playground.auth.data.RemotePlaygroundAuthDatasource -import org.sopt.official.playground.auth.data.remote.model.response.OauthToken +import org.sopt.official.playground.auth.data.remote.model.response.OAuthToken import org.sopt.official.playground.auth.utils.PlaygroundUriProvider object PlaygroundAuth { @@ -17,10 +17,11 @@ object PlaygroundAuth { context: Context, authStateGenerator: AuthStateGenerator = DefaultAuthStateGenerator(), uri: Uri? = null, + isDebug: Boolean = false, authDataSource: PlaygroundAuthDatasource = RemotePlaygroundAuthDatasource( - PlaygroundApiManager.getInstance().provideAuthService() + PlaygroundApiManager.getInstance(isDebug).provideAuthService() ), - callback: (Result) -> Unit + callback: (Result) -> Unit, ) { val stateToken = authStateGenerator.generate() val resultReceiver = resultReceiver(authDataSource) { @@ -28,7 +29,7 @@ object PlaygroundAuth { } startAuthTab( context = context, - uri = uri ?: PlaygroundUriProvider().authorize(state = stateToken), + uri = uri ?: PlaygroundUriProvider().authorize(state = stateToken, isDebug = isDebug), state = stateToken, resultReceiver = resultReceiver ) @@ -50,7 +51,7 @@ object PlaygroundAuth { private fun resultReceiver( authDataSource: PlaygroundAuthDatasource, - callback: (Result) -> Unit + callback: (Result) -> Unit ) = PlaygroundAuthResultReceiver( callback = { code, error -> if (error != null) { @@ -65,7 +66,7 @@ object PlaygroundAuth { private fun requestOauthToken( authDataSource: PlaygroundAuthDatasource, code: String, - callback: (Result) -> Unit + callback: (Result) -> Unit ) = CoroutineScope(Dispatchers.Default).launch { callback(authDataSource.oauth(code)) } diff --git a/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundInfo.kt b/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundInfo.kt index 907b05a..8b4fd7d 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundInfo.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/PlaygroundInfo.kt @@ -1,8 +1,10 @@ package org.sopt.official.playground.auth internal object PlaygroundInfo { - val HOST: String = "sopt-internal-dev.pages.dev" + val DEBUG_HOST: String = "sopt-internal-dev.pages.dev" + val HOST: String = "playground.sopt.org" val AUTH_PATH: String = "auth/oauth" val REDIRECT_URI = "app://org.sopt.makers.android/oauth2redirect" - val authHost: String = "mock-makers-app-server.tekiter.workers.dev" + val DEBUG_AUTH_HOST: String = "ec2-43-200-170-159.ap-northeast-2.compute.amazonaws.com:8080/api/v2/" + val RELEASE_AUTH_HOST: String = "app.sopt.org/api/v2/" } \ No newline at end of file diff --git a/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundApiManager.kt b/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundApiManager.kt index d10d910..62d48b5 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundApiManager.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundApiManager.kt @@ -16,14 +16,14 @@ internal class PlaygroundApiManager private constructor( @Volatile private var instance: PlaygroundApiManager? = null - fun getInstance() = instance ?: synchronized(this) { - instance ?: PlaygroundApiManager(createRetrofit()).also { + fun getInstance(isDebug: Boolean) = instance ?: synchronized(this) { + instance ?: PlaygroundApiManager(createRetrofit(isDebug)).also { instance = it } } - private fun createRetrofit() = ServiceFactory.withClient( - url = "${Constants.SCHEME}://${PlaygroundInfo.authHost}", + private fun createRetrofit(isDebug: Boolean) = ServiceFactory.withClient( + url = "${if (isDebug) Constants.NOT_SECURE_SCHEME else Constants.SCHEME}://${if (isDebug) PlaygroundInfo.DEBUG_AUTH_HOST else PlaygroundInfo.RELEASE_AUTH_HOST}", client = OkHttpClient.Builder() .addInterceptor(ServiceFactory.loggingInterceptor) .build() diff --git a/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundAuthDatasource.kt b/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundAuthDatasource.kt index 889cbe4..a7a3b7a 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundAuthDatasource.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/data/PlaygroundAuthDatasource.kt @@ -1,7 +1,7 @@ package org.sopt.official.playground.auth.data -import org.sopt.official.playground.auth.data.remote.model.response.OauthToken +import org.sopt.official.playground.auth.data.remote.model.response.OAuthToken interface PlaygroundAuthDatasource { - suspend fun oauth(code: String): Result + suspend fun oauth(code: String): Result } \ No newline at end of file diff --git a/auth/src/main/java/org/sopt/official/playground/auth/data/RemotePlaygroundAuthDatasource.kt b/auth/src/main/java/org/sopt/official/playground/auth/data/RemotePlaygroundAuthDatasource.kt index 47c0389..48a34a6 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/data/RemotePlaygroundAuthDatasource.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/data/RemotePlaygroundAuthDatasource.kt @@ -3,14 +3,14 @@ package org.sopt.official.playground.auth.data import org.sopt.official.playground.auth.PlaygroundError import org.sopt.official.playground.auth.data.remote.AuthService import org.sopt.official.playground.auth.data.remote.model.request.RequestToken -import org.sopt.official.playground.auth.data.remote.model.response.OauthToken +import org.sopt.official.playground.auth.data.remote.model.response.OAuthToken import java.net.UnknownHostException internal class RemotePlaygroundAuthDatasource( private val authService: AuthService ) : PlaygroundAuthDatasource { - override suspend fun oauth(code: String): Result { + override suspend fun oauth(code: String): Result { val result = kotlin.runCatching { authService.oauth(RequestToken(code)) } return when (val exception = result.exceptionOrNull()) { null -> result diff --git a/auth/src/main/java/org/sopt/official/playground/auth/data/remote/AuthService.kt b/auth/src/main/java/org/sopt/official/playground/auth/data/remote/AuthService.kt index 7d05958..8aea180 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/data/remote/AuthService.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/data/remote/AuthService.kt @@ -1,13 +1,13 @@ package org.sopt.official.playground.auth.data.remote import org.sopt.official.playground.auth.data.remote.model.request.RequestToken -import org.sopt.official.playground.auth.data.remote.model.response.OauthToken +import org.sopt.official.playground.auth.data.remote.model.response.OAuthToken import retrofit2.http.Body import retrofit2.http.POST internal interface AuthService { - @POST("oauth") + @POST("auth/playground") suspend fun oauth( @Body request: RequestToken - ): OauthToken + ): OAuthToken } \ No newline at end of file diff --git a/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/request/RequestToken.kt b/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/request/RequestToken.kt index 94771b0..200da91 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/request/RequestToken.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/request/RequestToken.kt @@ -1,8 +1,10 @@ package org.sopt.official.playground.auth.data.remote.model.request +import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable internal data class RequestToken( + @SerialName("code") val code: String ) \ No newline at end of file diff --git a/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/response/OauthToken.kt b/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/response/OauthToken.kt index ef13fe8..0fe01da 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/response/OauthToken.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/data/remote/model/response/OauthToken.kt @@ -4,7 +4,9 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class OauthToken( - @SerialName("access_token") - val accessToken: String -) \ No newline at end of file +data class OAuthToken( + @SerialName("accessToken") val accessToken: String, + @SerialName("refreshToken") val refreshToken: String, + @SerialName("playgroundToken") val playgroundToken: String, + @SerialName("status") val status: String +) diff --git a/auth/src/main/java/org/sopt/official/playground/auth/utils/PlaygroundUriProvider.kt b/auth/src/main/java/org/sopt/official/playground/auth/utils/PlaygroundUriProvider.kt index 7770715..29a87d1 100644 --- a/auth/src/main/java/org/sopt/official/playground/auth/utils/PlaygroundUriProvider.kt +++ b/auth/src/main/java/org/sopt/official/playground/auth/utils/PlaygroundUriProvider.kt @@ -6,11 +6,12 @@ import org.sopt.official.playground.auth.PlaygroundInfo internal class PlaygroundUriProvider { fun authorize( + isDebug: Boolean = false, redirectUri: String = PlaygroundInfo.REDIRECT_URI, state: String ): Uri = Uri.Builder() .scheme(Constants.SCHEME) - .authority(PlaygroundInfo.HOST) + .authority(if (isDebug) PlaygroundInfo.DEBUG_HOST else PlaygroundInfo.HOST) .path(PlaygroundInfo.AUTH_PATH) .appendQueryParameter(Constants.REDIRECT_URI, redirectUri) .appendQueryParameter(Constants.STATE, state) diff --git a/build.gradle b/build.gradle index eb0fa9a..59b3653 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - id 'com.android.application' version '8.0.0-beta04' apply false - id 'com.android.library' version '8.0.0-beta04' apply false + id 'com.android.application' version '7.4.1' apply false + id 'com.android.library' version '7.4.1' apply false id 'org.jetbrains.kotlin.android' version '1.8.0' apply false id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.0' id 'com.google.dagger.hilt.android' version '2.44' apply false diff --git a/example/build.gradle b/example/build.gradle index 99c216f..360db8d 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -38,7 +38,7 @@ android { } dependencies { - implementation 'com.github.sopt-makers:sopt-android-pgauth:0.1.2' + implementation project(':auth') implementation 'androidx.core:core-ktx:1.9.0' diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index ec55a05..0c291fd 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -14,6 +14,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.AuthExample" + android:usesCleartextTraffic="true" tools:targetApi="31"> + authViewModel.loginEventStream.collect { + PlaygroundAuth.authorizeWithWebTab( + this@MainActivity, + isDebug = false + ) { result -> result.onSuccess { authViewModel.completeLogin(it.accessToken) }.onFailure { exception ->