Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Patch] Revoke OAuth tokens at sample start #239

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,31 @@ import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.toolkit.authentication.DialogAuthenticator
import com.arcgismaps.toolkit.authentication.signOut
import com.esri.arcgismaps.sample.authenticatewithoauth.components.MapViewModel
import com.esri.arcgismaps.sample.authenticatewithoauth.screens.MainScreen
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the API key also be nulled out here, same as you did in Create And Safe Map sample?

// Remove any API key already set
// The concurrent use of an API key and user authentication is not supported
ArcGISEnvironment.apiKey = null

// Sign out of any portals which are already authenticated
lifecycleScope.launch(Dispatchers.Main) {
ArcGISEnvironment.authenticationManager.signOut()
}

setContent {
SampleAppTheme {
AuthenticateWithOAuthApp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.viewmodel.compose.viewModel
import com.arcgismaps.ArcGISEnvironment
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.createandsavemap.screens.MainScreen
import com.arcgismaps.toolkit.authentication.DialogAuthenticator
import com.arcgismaps.toolkit.authentication.signOut
import com.esri.arcgismaps.sample.createandsavemap.components.MapViewModel
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MainActivity : ComponentActivity() {

Expand All @@ -40,28 +42,29 @@ class MainActivity : ComponentActivity() {
ArcGISEnvironment.apiKey = null

// Sign out of any portals which are already authenticated
runBlocking {
lifecycleScope.launch(Dispatchers.Main) {
ArcGISEnvironment.authenticationManager.signOut()
}
setContent {
SampleAppTheme {
SampleApp()

setContent {
SampleAppTheme {
CreateAndSaveMapApp()
}
}
}
}

@Composable
private fun SampleApp() {
private fun CreateAndSaveMapApp() {
val mapViewModel: MapViewModel = viewModel()
Surface(
color = MaterialTheme.colorScheme.background
) {
MainScreen(
sampleName = getString(R.string.app_name)
)
}

// authenticator at bottom can draw over the top of the sample
DialogAuthenticator(authenticatorState = mapViewModel.authenticatorState)
// authenticator at bottom can draw over the top of the sample
DialogAuthenticator(authenticatorState = mapViewModel.authenticatorState)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MenuAnchorType
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SheetValue
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
Expand Down Expand Up @@ -87,9 +89,10 @@ fun MainScreen(sampleName: String) {
val composableScope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
val controlsBottomSheetState = rememberBottomSheetScaffoldState(
bottomSheetState = rememberStandardBottomSheetState(skipHiddenState = false).apply {
composableScope.launch { hide() }
}
bottomSheetState = rememberStandardBottomSheetState(
initialValue = SheetValue.Hidden,
skipHiddenState = false
)
)

Scaffold(
Expand Down Expand Up @@ -274,7 +277,7 @@ fun FolderDropdown(
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.menuAnchor(),
.menuAnchor(MenuAnchorType.PrimaryNotEditable),
value = label,
onValueChange = { newDescription -> label = newDescription },
label = { Text(text = "Folder:") },
Expand Down Expand Up @@ -339,7 +342,7 @@ fun BasemapDropdown(
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.menuAnchor(),
.menuAnchor(MenuAnchorType.PrimaryNotEditable),
value = basemapStyle,
onValueChange = {},
label = { Text(text = "Basemap Style:") },
Expand Down Expand Up @@ -390,7 +393,7 @@ fun LayersDropdown(
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
.menuAnchor(),
.menuAnchor(MenuAnchorType.PrimaryNotEditable),
value = "Select...",
onValueChange = {},
label = { Text(text = "Operational Layers:") },
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ktxAndroidCore = "1.13.0"
kotlinCompilerExt = "1.5.12"
# Compose versions
composeActivityVersion = "1.9.0"
composeBOM = "2024.04.01"
composeBOM = "2024.09.03"
# Library versions
appcompatVersion = "1.6.1"
commonsIoVersion = "2.15.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@ import androidx.activity.compose.setContent
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
import androidx.lifecycle.lifecycleScope
import com.arcgismaps.ArcGISEnvironment
import com.arcgismaps.toolkit.authentication.signOut
import com.esri.arcgismaps.sample.sampleslib.theme.SampleAppTheme
import com.esri.arcgismaps.sample.showportaluserinfo.screens.MainScreen
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// authentication with an API key or named user is
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.API_KEY)

// Sign out of any portals which are already authenticated
lifecycleScope.launch(Dispatchers.Main) {
ArcGISEnvironment.authenticationManager.signOut()
}

setContent {
SampleAppTheme {
Expand Down
Loading