Exemplo n.º 1
0
        private async Task <MSACredentials> PostAuthCodeAsync(
            FormUrlEncodedContent data,
            CancellationTokenSource cts = null)
        {
            var postRequest = new FormUrlEncodedJsonPostNetworkRequest(new HttpClient(), TokenUri, data);

            var retryCall = false;

            try
            {
                return(await postRequest.ExecuteAsync <MSACredentials>(cts));
            }
            catch (HttpRequestException hre) when(hre.Message.Contains("401"))
            {
                var tokenRefreshed = await this.ExchangeRefreshTokenAsync();

                if (tokenRefreshed != null)
                {
                    retryCall = true;
                }
            }

            if (retryCall)
            {
                postRequest = new FormUrlEncodedJsonPostNetworkRequest(new HttpClient(), TokenUri, data);
                return(await postRequest.ExecuteAsync <MSACredentials>(cts));
            }

            return(default(MSACredentials));
        }
Exemplo n.º 2
0
        private async Task <MSACredentials> PostAuthCodeAsync(
            FormUrlEncodedContent data,
            CancellationToken cancellationToken = default)
        {
            var postRequest =
                new FormUrlEncodedJsonPostNetworkRequest(this.httpClient, TokenUri, data);

            bool retryCall = false;

            try
            {
                return(await postRequest.ExecuteAsync <MSACredentials>(cancellationToken));
            }
            catch (HttpRequestException hre) when(hre.Message.Contains("401"))
            {
                MSACredentials tokenRefreshed = await this.ExchangeRefreshTokenAsync(cancellationToken);

                if (tokenRefreshed != null)
                {
                    retryCall = true;
                }
            }

            if (!retryCall)
            {
                return(default);