Select to view content in your preferred language

Portal sign-out and new sign-in not working as expected

261
1
05-22-2024 03:20 AM
mmoosbac94
New Contributor

Hello everybody,

we have a question regarding a portal sign-out and a new sign-in without re-initializing portal and without restarting the app. The first login is working fine but when we logout (revoking and removing stored credentials) we would expect to receive a new challenge when calling portal.load() again and wait for portal.load() to complete the challenge and then continue in the code. But this ends in a weird behaviour, because portal.load() does not wait for challenge to complete. We are using a custom ArcGISAuthenticationChallengeHandler for handling challenges. We found out that after a sign-out with removing credentials, portal.load() is still in the loaded state when we try to sign-in after a sign-out and the load() function completes immediately which causes the weird behaviour in the app of course. Because at this point (the load() function) in the code it should stop and wait for the new challenge to complete and continue after successful sign-in. Why is that? Is the solution to re-initialize the portal-object again so that is in unloaded state or can we maybe reset the portal state from loaded to unloaded? For better understanding here is a code sample:

func signIn() async {
        DispatchQueue.main.async {
            self.isLoading = true
        }
        do {
            try await setupPersistentCredentialStorage()
            try await loadPortal()
            isloggedIn = true
            isLoading = false
        } catch {
            handleSignInError(error)
        }
    }

func removeCredentials() async {
        await ArcGISEnvironment.authenticationManager.revokeOAuthTokens()
        await ArcGISEnvironment.authenticationManager.clearCredentialStores()
    }

 func removeCredentialsAndLogout() {
        Task {
            await removeCredentials()
            DispatchQueue.main.async {
                self.isLoggedIn = false
            }
        }
    }

 

0 Kudos
1 Reply
Nicholas-Furness
Esri Regular Contributor

Hello. Thanks for the question.

This is expected behavior. Loadable is all about metadata, not object state. The Portal's metadata is loaded once from the actual ArcGIS Online or ArcGIS Enterprise portal, and that doesn't change just because you revoke the credentials that provide access to it. There's some great info here about how the Loadable pattern works, and you can see that once a Loadable object reaches loaded state, it'll stay there. Calling load() on a loaded object is essentially a no-op.

When you first call load() on the portal, it needs to load metadata about that portal as mentioned above, and since most (all?) of that metadata requires authentication to read, you see the authentication prompt and caching of credentials.

I would create a new indentical Portal object and load that.

Hope that helps!

0 Kudos