/// <summary> /// Log out of the system. /// </summary> /// <returns></returns> public async Task LogoutAsync() { if (Client.CurrentUser == null || Client.CurrentUser.MobileServiceAuthenticationToken == null) { return; } // Log out of the identity provider (if required) // review: https://github.com/adrianhall/develop-mobile-apps-with-csharp-and-azure/blob/master/Chapter3/TaskList/TaskList/Services/AzureCloudService.cs // Invalidate the token on the mobile backend (// Remove the token from the token store) var authUri = new Uri($"{Client.MobileAppUri}/.auth/logout"); using (var httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("X-ZUMO-AUTH", Client.CurrentUser.MobileServiceAuthenticationToken); await httpClient.GetAsync(authUri); } // Remove the token from the cache LoginProvider.RemoveTokenFromSecureStore(); Settings.AccessToken = ""; Settings.ResetAll(); //Purge items from local storage var force = true; await sharingSpaceTable.PurgeAsync("PurgeQuery", null, force, CancellationToken.None); // Remove the token from the MobileServiceClient await Client.LogoutAsync(); }