Esempio n. 1
0
        public async Task ClearCookiesAsync(LoginOptions options)
        {
            if (Window.Current == null)
            {
                return;
            }
            var frame = Window.Current.Content as Frame;

            if (frame != null)
            {
                await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var loginUri = new Uri(OAuth2.ComputeAuthorizationUrl(options));
                    var myFilter = new HttpBaseProtocolFilter();
                    HttpCookieManager cookieManager = myFilter.CookieManager;
                    try
                    {
                        LoggingService.Log("attempting to clear cookies", LoggingLevel.Verbose);
                        HttpCookieCollection cookies = cookieManager.GetCookies(loginUri);
                        foreach (HttpCookie cookie in cookies)
                        {
                            cookieManager.DeleteCookie(cookie);
                        }
                        LoggingService.Log("clear cookies done", LoggingLevel.Verbose);
                    }
                    catch (ArgumentException ex)
                    {
                        LoggingService.Log("Exception occurred when clearing cookies", LoggingLevel.Critical);
                        LoggingService.Log(ex, LoggingLevel.Critical);
                    }
                });
            }
        }
        public static async void ClearCookies(LoginOptions loginOptions)
        {
            var frame = Window.Current.Content as Frame;

            if (frame != null)
            {
                await frame.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    var loginUri = new Uri(ComputeAuthorizationUrl(loginOptions));
                    var myFilter = new HttpBaseProtocolFilter();
                    HttpCookieManager cookieManager = myFilter.CookieManager;
                    try
                    {
                        PlatformAdapter.SendToCustomLogger("OAuth.ClearCookies - attempting at clearing cookies", LoggingLevel.Verbose);
                        HttpCookieCollection cookies = cookieManager.GetCookies(loginUri);
                        foreach (HttpCookie cookie in cookies)
                        {
                            cookieManager.DeleteCookie(cookie);
                        }
                        PlatformAdapter.SendToCustomLogger("OAuth2.ClearCookies - done", LoggingLevel.Verbose);
                    }
                    catch (ArgumentException ex)
                    {
                        PlatformAdapter.SendToCustomLogger("OAuth2.ClearCookies - Exception occurred when clearing cookies:", LoggingLevel.Critical);
                        PlatformAdapter.SendToCustomLogger(ex, LoggingLevel.Critical);
                        Debug.WriteLine("Error clearing cookies");
                    }
                });
            }
        }
Esempio n. 3
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            scopes = e.Parameter as List <TwitchConstants.Scope>;
            Uri authPageUri = AppConstants.Twixel.Login(scopes);
            HttpBaseProtocolFilter filter        = new HttpBaseProtocolFilter();
            HttpCookieManager      cookieManager = filter.CookieManager;
            HttpCookieCollection   cookies       = cookieManager.GetCookies(authPageUri);

            foreach (HttpCookie cookie in cookies)
            {
                cookieManager.DeleteCookie(cookie);
            }
            webView.Navigate(authPageUri);
            base.OnNavigatedTo(e);
        }
Esempio n. 4
0
        private void ClearCookie()
        {
            if (Uri.TryCreate(AuthorizeUrl, UriKind.Absolute, out var authUri))
            {
                // capture the domain of the OAuth URL, then clear all cookies
                string targetUrl = $"{authUri.Scheme}://{authUri.Host}";

                HttpBaseProtocolFilter filter     = new HttpBaseProtocolFilter();
                HttpCookieManager      manager    = filter.CookieManager;
                HttpCookieCollection   collection = manager.GetCookies(new Uri(targetUrl));

                foreach (var item in collection)
                {
                    manager.DeleteCookie(item);
                }
            }
        }