protected virtual async Task <PublicKeyX509Certificate> GetPublicKeyAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            try
            {
                var sessionConfigBuilder = new SessionConfigUrlBuilder(this.restGrammar, this.webApiGrammar);
                var taskFlow             = new GetPublicKeyTasks(sessionConfigBuilder, this.restGrammar, this.webApiGrammar, this.httpClient);

                PublicKeyX509Certificate result = await RestApiCallFlow.LoadRequestFromNetworkFlow(this.sessionConfig, taskFlow, cancelToken);

                this.publicCertifiacte = result;
            }
            catch (ObjectDisposedException)
            {
                // CancellationToken.ThrowIfCancellationRequested()
                throw;
            }
            catch (OperationCanceledException)
            {
                // CancellationToken.ThrowIfCancellationRequested()
                // and TaskCanceledException
                throw;
            }
            catch (SitecoreMobileSdkException ex)
            {
                // throw unwrapped exception as if GetPublicKeyAsync() is an atomic phase
                throw new RsaHandshakeException("[Sitecore Mobile SDK] Public key not received properly", ex.InnerException);
            }
            catch (Exception ex)
            {
                throw new RsaHandshakeException("[Sitecore Mobile SDK] Public key not received properly", ex);
            }

            return(this.publicCertifiacte);
        }
        protected virtual async Task <ScAuthResponse> GetPublicKeyAsync(CancellationToken cancelToken = default(CancellationToken))
        {
            ScAuthResponse response = null;

            if (this.credentials != null)
            {
                string url = SessionConfigValidator.AutocompleteInstanceUrlForcingHttps(this.Config.InstanceUrl);
                IEnumerable <Cookie> prevCookies = this.cookies.GetCookies(new Uri(url)).Cast <Cookie>();
                bool noCookies = true;

                if (prevCookies.Count() > 0)
                {
                    noCookies = this.CookiesExpired(prevCookies);
                }

                if (noCookies)
                {
                    try {
                        var sessionConfigBuilder = new SessionConfigUrlBuilder(this.restGrammar, this.sscGrammar);
                        var taskFlow             = new GetPublicKeyTasks(this.credentials, sessionConfigBuilder, this.sscGrammar, this.httpClient);

                        response = await RestApiCallFlow.LoadRequestFromNetworkFlow(this.sessionConfig, taskFlow, cancelToken);

                        IEnumerable <Cookie> newCookies = this.cookies.GetCookies(new Uri(url)).Cast <Cookie>();
                        Debug.WriteLine(newCookies.ToString());
                    } catch (ObjectDisposedException) {
                        // CancellationToken.ThrowIfCancellationRequested()
                        throw;
                    } catch (OperationCanceledException) {
                        // CancellationToken.ThrowIfCancellationRequested()
                        // and TaskCanceledException
                        throw;
                    } catch (SitecoreMobileSdkException ex) {
                        // throw unwrapped exception as if GetPublicKeyAsync() is an atomic phase
                        throw new RsaHandshakeException("[Sitecore Mobile SDK] ASPXAUTH not received properly", ex.InnerException);
                    } catch (Exception ex) {
                        throw new RsaHandshakeException("[Sitecore Mobile SDK] ASPXAUTH not received properly", ex);
                    }
                }
                else
                {
                    response = new ScAuthResponse("200");
                }
            }

            return(response);
        }
    protected virtual async Task<PublicKeyX509Certificate> GetPublicKeyAsync(CancellationToken cancelToken = default(CancellationToken))
    {
      try
      {
        var sessionConfigBuilder = new SessionConfigUrlBuilder(this.restGrammar, this.webApiGrammar);
        var taskFlow = new GetPublicKeyTasks(sessionConfigBuilder, this.restGrammar, this.webApiGrammar, this.httpClient);

        PublicKeyX509Certificate result = await RestApiCallFlow.LoadRequestFromNetworkFlow(this.sessionConfig, taskFlow, cancelToken);
        this.publicCertifiacte = result;
      }
      catch (ObjectDisposedException)
      {
        // CancellationToken.ThrowIfCancellationRequested()
        throw;
      }
      catch (OperationCanceledException)
      {
        // CancellationToken.ThrowIfCancellationRequested()
        // and TaskCanceledException
        throw;
      }
      catch (SitecoreMobileSdkException ex)
      {
        // throw unwrapped exception as if GetPublicKeyAsync() is an atomic phase
        throw new RsaHandshakeException("[Sitecore Mobile SDK] Public key not received properly", ex.InnerException);
      }
      catch (Exception ex)
      {
        throw new RsaHandshakeException("[Sitecore Mobile SDK] Public key not received properly", ex);
      }

      return this.publicCertifiacte;
    }