Skip to content

Commit

Permalink
Fix profile fetch after OAuth
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolnai committed Nov 14, 2023
1 parent 8010b24 commit 8a7405c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -85,8 +84,7 @@ fun SelectProfileScreen(
snapshotFlow { viewModel.uiState }
.filter { it.checkProfileWhenResuming }
.flowWithLifecycle(lifecycle)
.collect { state ->
awaitFrame()
.collect { _ ->
viewModel.checkIfCurrentProfileHasAccess()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 8a7405c

Please sign in to comment.