AGSPortal.logout() does nothing?

593
3
07-05-2019 11:09 AM
SteveMiller4
New Contributor II

I'm trying to call .logout() on a portal that a user has successfully logged in to, but the call seems to do nothing. After calling it, portal.user and portal.portalInfo are still set, and the loadStatus is still .loaded . Is this the expected behavior or a bug?

0 Kudos
3 Replies
NimeshJarecha
Esri Regular Contributor

Hi Steve,

The API ref doc for the `logout` method states what it does. It does operation to the credential and does not change the load status of portal object. After calling `logout`, you should set portal object to nil if you are no longer required.

logout - If there is a credential for this portal then it will be set to nil and remove it from credential cache. If credential is of type OAuth then token will be invalidated.

Hope this helps!

Regards,

Nimesh

0 Kudos
Nicholas-Furness
Esri Regular Contributor

[Edited just to add some thoughts since Nimesh already replied]

The loadStatus is to do with Runtime having loaded enough metadata to make the AGSPortal instance usable, so that shouldn't change.

I would also expect portalInfo (metadata) and user properties to remain unchanged. The user info may still be useful to you, even if Runtime no longer has a valid credential for it.

So, when you call logout(), Runtime will invalidate the token (and AGSCredential) being used by the AGSPortal. If you perform another operation that requires authentication, it will fail and trigger an authentication workflow (e.g. OAuth, or just ask you for username and password, depending on how your app is configured).

This API is left over from some earlier designs. We are working on a clearer API which will control credential validity through the AGSAuthenticationManager.

0 Kudos
SteveMiller4
New Contributor II

Alright, that explains why the data-collection sample calls

AuthenticationManager.shared().credentialCache.removeAllCredentials()

instead of .logout()

Thanks for the clarifications.

0 Kudos