diff --git a/Documentation/ConfigurationManagement.md b/Documentation/ConfigurationManagement.md index 548e84759..c232e6dad 100644 --- a/Documentation/ConfigurationManagement.md +++ b/Documentation/ConfigurationManagement.md @@ -38,7 +38,7 @@ Open `config.yaml` and fill in the required fields. Example: ```yaml -API_HOST_URL: 'https://mylmsexample.com' +API_HOST_URL: 'https://4c1346f74eb5.ngrok-free.app' APPLICATION_ID: 'org.openedx.app' ENVIRONMENT_DISPLAY_NAME: 'MyLMSExample' FEEDBACK_EMAIL_ADDRESS: 'support@mylmsexample.com' diff --git a/auth/src/main/java/org/openedx/auth/data/api/AuthApi.kt b/auth/src/main/java/org/openedx/auth/data/api/AuthApi.kt index b837648fe..3c4eaf0c7 100644 --- a/auth/src/main/java/org/openedx/auth/data/api/AuthApi.kt +++ b/auth/src/main/java/org/openedx/auth/data/api/AuthApi.kt @@ -13,6 +13,7 @@ import retrofit2.http.FormUrlEncoded import retrofit2.http.GET import retrofit2.http.POST import retrofit2.http.Path +import retrofit2.Response interface AuthApi { @@ -35,7 +36,7 @@ interface AuthApi { @Field("password") password: String, @Field("token_type") tokenType: String, @Field("asymmetric_jwt") isAsymmetricJwt: Boolean = true, - ): AuthResponse + ): Response @FormUrlEncoded @POST(ApiConstants.URL_ACCESS_TOKEN) diff --git a/auth/src/main/java/org/openedx/auth/data/repository/AuthRepository.kt b/auth/src/main/java/org/openedx/auth/data/repository/AuthRepository.kt index 20499baf9..4929e1c5d 100644 --- a/auth/src/main/java/org/openedx/auth/data/repository/AuthRepository.kt +++ b/auth/src/main/java/org/openedx/auth/data/repository/AuthRepository.kt @@ -9,6 +9,7 @@ import org.openedx.core.config.Config import org.openedx.core.data.storage.CorePreferences import org.openedx.core.domain.model.RegistrationField import org.openedx.core.system.EdxError +import android.util.Log class AuthRepository( private val config: Config, @@ -16,21 +17,31 @@ class AuthRepository( private val preferencesManager: CorePreferences, ) { - suspend fun login( - username: String, - password: String, - ) { - api.getAccessToken( - ApiConstants.GRANT_TYPE_PASSWORD, - config.getOAuthClientId(), - username, - password, - config.getAccessTokenType(), - ) - .mapToDomain() - .processAuthResponse() + suspend fun login(username: String, password: String): Result { + return try { + val response = api.getAccessToken( + grantType = "password", + clientId = "android", + username = username, + password = password, + tokenType = "JWT", // from your config (TOKEN_TYPE in JSON) + isAsymmetricJwt = true // default, you can omit if always true + ) + if (response.isSuccessful) { + response.body()?.let { + Result.success(it.mapToDomain()) + } ?: Result.failure(Exception("Empty response")) + } else { + val errorMsg = response.errorBody()?.string() ?: "Unknown error" + Result.failure(Exception(errorMsg)) + } + + } catch (e: Exception) { + Result.failure(e) + } } + suspend fun socialLogin(token: String?, authType: AuthType) { require(!token.isNullOrBlank()) { "Token is null" } api.exchangeAccessToken( diff --git a/build.gradle b/build.gradle index 390d02699..24df6490f 100644 --- a/build.gradle +++ b/build.gradle @@ -14,8 +14,8 @@ buildscript { } plugins { - id 'com.android.application' version '8.5.2' apply false - id 'com.android.library' version '8.5.2' apply false + id 'com.android.application' version '8.12.2' apply false + id 'com.android.library' version '8.12.2' apply false id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false id 'com.google.gms.google-services' version '4.4.2' apply false id "com.google.firebase.crashlytics" version "3.0.2" apply false diff --git a/default_config/dev/config.yaml b/default_config/dev/config.yaml index 4d1d694ec..bbe3db3ad 100644 --- a/default_config/dev/config.yaml +++ b/default_config/dev/config.yaml @@ -1,4 +1,4 @@ -API_HOST_URL: 'http://localhost:8000' +API_HOST_URL: 'https://4c1346f74eb5.ngrok-free.app' APPLICATION_ID: 'org.openedx.app' ENVIRONMENT_DISPLAY_NAME: 'Localhost' URI_SCHEME: '' diff --git a/default_config/prod/config.yaml b/default_config/prod/config.yaml index 4d1d694ec..bbe3db3ad 100644 --- a/default_config/prod/config.yaml +++ b/default_config/prod/config.yaml @@ -1,4 +1,4 @@ -API_HOST_URL: 'http://localhost:8000' +API_HOST_URL: 'https://4c1346f74eb5.ngrok-free.app' APPLICATION_ID: 'org.openedx.app' ENVIRONMENT_DISPLAY_NAME: 'Localhost' URI_SCHEME: '' diff --git a/default_config/stage/config.yaml b/default_config/stage/config.yaml index 4d1d694ec..bbe3db3ad 100644 --- a/default_config/stage/config.yaml +++ b/default_config/stage/config.yaml @@ -1,4 +1,4 @@ -API_HOST_URL: 'http://localhost:8000' +API_HOST_URL: 'https://4c1346f74eb5.ngrok-free.app' APPLICATION_ID: 'org.openedx.app' ENVIRONMENT_DISPLAY_NAME: 'Localhost' URI_SCHEME: '' diff --git a/default_config/user_config.yaml b/default_config/user_config.yaml new file mode 100644 index 000000000..b7caad238 --- /dev/null +++ b/default_config/user_config.yaml @@ -0,0 +1,12 @@ +API_HOST_URL: "https://4c1346f74eb5.ngrok-free.app" +PLATFORM_NAME: "Soham's Local edX" +ENVIRONMENT_DISPLAY_NAME: "Local Dev" +OAUTH_CLIENT_ID: "android" +DISCOVERY: + TYPE: native +FIREBASE: + ENABLED: false +MICROSOFT: + ENABLED: false +FACEBOOK: + ENABLED: false diff --git a/discovery/src/test/java/org/openedx/discovery/presentation/NativeDiscoveryViewModelTest.kt b/discovery/src/test/java/org/openedx/discovery/presentation/NativeDiscoveryViewModelTest.kt index 9a88b445a..a1a81f623 100644 --- a/discovery/src/test/java/org/openedx/discovery/presentation/NativeDiscoveryViewModelTest.kt +++ b/discovery/src/test/java/org/openedx/discovery/presentation/NativeDiscoveryViewModelTest.kt @@ -58,7 +58,7 @@ class NativeDiscoveryViewModelTest { every { resourceManager.getString(R.string.core_error_unknown_error) } returns somethingWrong every { appNotifier.notifier } returns emptyFlow() every { corePreferences.user } returns null - every { config.getApiHostURL() } returns "http://localhost:8000" + every { config.getApiHostURL() } returns "https://4c1346f74eb5.ngrok-free.app" every { config.isPreLoginExperienceEnabled() } returns false } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ec34fd6a7..9926dc016 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Fri May 03 13:24:00 EEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists