Exemple #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 void TestComputeAuthorizationUrl()
        {
            string loginUrl    = "https://login.salesforce.com";
            string clientId    = "TEST_CLIENT_ID";
            string callbackUrl = "test://sfdc";

            string[]     scopes       = { "web", "api" };
            LoginOptions loginOptions = new LoginOptions(loginUrl, clientId, callbackUrl, scopes);

            string expectedUrl = "https://login.salesforce.com/services/oauth2/authorize?display=touch&response_type=token&client_id=TEST_CLIENT_ID&redirect_uri=test://sfdc&scope=web%20api%20refresh_token";
            string actualUrl   = OAuth2.ComputeAuthorizationUrl(loginOptions);

            Assert.AreEqual(expectedUrl, actualUrl, "Wrong authorization url");
        }