Beispiel #1
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (this.Client == null)
            {
                throw new InvalidOperationException("Make sure to set the 'Client' property in this handler before using it.");
            }

            // Cloning the request, in case we need to send it again
            var clonedRequest = await CloneRequestAsync(request);

            var response = await base.SendAsync(clonedRequest, cancellationToken);

            if (response.StatusCode == HttpStatusCode.Unauthorized)
            {
                try {
                    AuthStore.DeleteTokenCache(); // cached token was invalid, so should clear it
                    await DoLoginAsync(Settings.Current.AuthenticationType);

                    clonedRequest = await CloneRequestAsync(request);

                    clonedRequest.Headers.Remove("X-ZUMO-AUTH");
                    clonedRequest.Headers.Add("X-ZUMO-AUTH", Client.CurrentUser.MobileServiceAuthenticationToken);

                    // Resend the request
                    response = await base.SendAsync(clonedRequest, cancellationToken);
                }
                catch (InvalidOperationException) {
                    // user cancelled auth, so return the original response
                    return(response);
                }
            }

            return(response);
        }
        public async Task LogoutAsync()
        {
            LoginManager.Instance.LogOut();

            CookieManager.Instance.RemoveAllCookie();
            AuthStore.DeleteTokenCache();
            await App.Instance.MobileService.LogoutAsync();
        }
        public async Task LogoutAsync()
        {
            foreach (var cookie in NSHttpCookieStorage.SharedStorage.Cookies)
            {
                NSHttpCookieStorage.SharedStorage.DeleteCookie(cookie);
            }

            AuthStore.DeleteTokenCache();
            await App.Instance.MobileService.LogoutAsync();
        }