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 1 commit
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 @@ -23,16 +23,24 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
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.runBlocking

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?

// Sign out of any portals which are already authenticated
runBlocking {
ArcGISEnvironment.authenticationManager.signOut()
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not recommended to use runBlocking in production code. The alternative here is to launch a coroutine on the Main dispatcher, then tdo the sign out followed by displaying the app:

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

Same change would need to be made to Show Portal User Info & Create And Save Map samples.

setContent {
SampleAppTheme {
AuthenticateWithOAuthApp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import com.arcgismaps.ApiKey
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.runBlocking

class MainActivity : ComponentActivity() {

Expand All @@ -35,6 +37,11 @@ class MainActivity : ComponentActivity() {
// required to access basemaps and other location services
ArcGISEnvironment.apiKey = ApiKey.create(BuildConfig.API_KEY)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we be setting an API key here, since the sample uses a named user?

\cc @shubham7109


// Sign out of any portals which are already authenticated
runBlocking {
ArcGISEnvironment.authenticationManager.signOut()
}

setContent {
SampleAppTheme {
ShowPortalUserInfoApp()
Expand Down
Loading