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

Conversation

01smito01
Copy link
Collaborator

Description

Change "Show portal user info" and "Authenticate with OAuth" to remove any cached authentication from ArcGISEnvironment. This makes them behave properly in the sample viewer even after a user has authenticated in another sample

Links and Data

Sample Epic: #4755

  • a vTest Job for this PR has been run

What To Review

  • Do the samples now behave as expected in the sample viewer?
  • Is runBlocking the best way to implement this?

How to Test

Run the samples in the sample viewer. Do they present an authentication challenge after completing one in another sample?

@01smito01 01smito01 added the Patch A patch to an existing sample label Oct 10, 2024
@01smito01 01smito01 self-assigned this Oct 10, 2024
Comment on lines 39 to 43
// 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.

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?

@@ -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

@shubham7109
Copy link
Collaborator

shubham7109 commented Oct 16, 2024

This PR will be replaced with #244 to apply these changes on the SV level.

There are some parceling issues to iron out currently, and once completed I would request a review from @01smito01 / @gunt0001

@01smito01
Copy link
Collaborator Author

Closing as #244 should be done this release. Will draft a new PR for removing the existing workflow from Create & Save Map.

@01smito01 01smito01 closed this Oct 21, 2024
@01smito01 01smito01 deleted the oliver/oauth-fixes branch November 21, 2024 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Patch A patch to an existing sample
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants