From 8a7405c9d97d399dfaf0ffc9beef49e703f2c141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Zolnai?= Date: Tue, 14 Nov 2023 14:22:37 +0100 Subject: [PATCH] Fix profile fetch after OAuth --- .../eduroam/geteduroam/config/model/EAPIdentityProvider.kt | 2 +- .../app/eduroam/geteduroam/profile/SelectProfileScreen.kt | 4 +--- .../eduroam/geteduroam/profile/SelectProfileViewModel.kt | 6 +++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/java/app/eduroam/geteduroam/config/model/EAPIdentityProvider.kt b/android/app/src/main/java/app/eduroam/geteduroam/config/model/EAPIdentityProvider.kt index 62d946c..3b60a58 100644 --- a/android/app/src/main/java/app/eduroam/geteduroam/config/model/EAPIdentityProvider.kt +++ b/android/app/src/main/java/app/eduroam/geteduroam/config/model/EAPIdentityProvider.kt @@ -7,7 +7,7 @@ import org.simpleframework.xml.ElementList import org.simpleframework.xml.Root -@Root(name = "EAPIdentityProvider") +@Root(name = "EAPIdentityProvider", strict = false) @JsonClass(generateAdapter = true) class EAPIdentityProvider { diff --git a/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileScreen.kt b/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileScreen.kt index 39fa376..9cae719 100644 --- a/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileScreen.kt +++ b/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileScreen.kt @@ -74,7 +74,6 @@ fun SelectProfileScreen( .filter { it.promptForOAuth } .flowWithLifecycle(lifecycle) .collect { state -> - awaitFrame() val profile = state.profiles.first { it.isSelected }.profile viewModel.setOAuthFlowStarted() currentGotoOauth(profile.createConfiguration()) @@ -85,8 +84,7 @@ fun SelectProfileScreen( snapshotFlow { viewModel.uiState } .filter { it.checkProfileWhenResuming } .flowWithLifecycle(lifecycle) - .collect { state -> - awaitFrame() + .collect { _ -> viewModel.checkIfCurrentProfileHasAccess() } } diff --git a/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileViewModel.kt b/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileViewModel.kt index 0906a2d..64a1400 100644 --- a/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileViewModel.kt +++ b/android/app/src/main/java/app/eduroam/geteduroam/profile/SelectProfileViewModel.kt @@ -3,7 +3,6 @@ package app.eduroam.geteduroam.profile import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import androidx.compose.ui.res.stringResource import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope @@ -14,7 +13,6 @@ import app.eduroam.geteduroam.config.model.ClientSideCredential import app.eduroam.geteduroam.config.model.EAPIdentityProviderList import app.eduroam.geteduroam.di.api.GetEduroamApi import app.eduroam.geteduroam.di.repository.StorageRepository -import app.eduroam.geteduroam.models.Configuration import app.eduroam.geteduroam.models.Profile import app.eduroam.geteduroam.ui.ErrorData import dagger.hilt.android.lifecycle.HiltViewModel @@ -23,6 +21,7 @@ import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch import okhttp3.OkHttpClient import okhttp3.Request +import okhttp3.RequestBody.Companion.toRequestBody import timber.log.Timber import javax.inject.Inject @@ -132,7 +131,7 @@ class SelectProfileViewModel @Inject constructor( Timber.i("Already authenticated for this profile, continue with existing credentials") val authState = repository.authState.first() viewModelScope.launch(Dispatchers.IO) { - getEapFrom(profile.eapconfigEndpoint, authState?.accessToken.orEmpty()) + getEapFrom(profile.eapconfigEndpoint, authState?.accessToken?.let { "Bearer $it" }) } } else if (startOAuthFlowIfNoAccess) { Timber.i("Prompt for authentication for selected profile.") @@ -168,6 +167,7 @@ class SelectProfileViewModel @Inject constructor( val client = OkHttpClient.Builder().build() var requestBuilder = Request.Builder() .url(url) + .method("POST", byteArrayOf().toRequestBody()) if (authorizationHeader != null) { requestBuilder = requestBuilder.addHeader("Authorization", authorizationHeader) }