Inheritance: IYubicoResponse
Exemplo n.º 1
0
        private static IYubicoResponse DoVerify(string url, string userAgent)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);

            if (userAgent == null)
            {
                request.UserAgent = "YubicoDotNetClient version:" + Assembly.GetExecutingAssembly().GetName().Version;
            }
            else
            {
                request.UserAgent = userAgent;
            }

            request.Timeout = 15000;

            HttpWebResponse rawResponse;

            try
            {
                rawResponse = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException)
            {
                return(null);
            }

            using (var dataStream = rawResponse.GetResponseStream())
            {
                if (dataStream != null)
                {
                    using (var reader = new StreamReader(dataStream))
                    {
                        IYubicoResponse response;

                        try
                        {
                            response = new YubicoResponse(reader.ReadToEnd());
                        }
                        catch (ArgumentException)
                        {
                            return(null);
                        }

                        if (response.Status == YubicoResponseStatus.ReplayedRequest)
                        {
                            //throw new YubicoValidationException("Replayed request, this otp & nonce combination has been seen before.");
                            return(null);
                        }

                        return(response);
                    }
                }
            }

            throw new YubicoValidationException();
        }
Exemplo n.º 2
0
        private async static Task <IYubicoResponse> DoVerifyAsync(string url, string userAgent, CancellationToken token)
        {
            var request = new HttpRequestMessage
            {
                Method     = HttpMethod.Get,
                RequestUri = new Uri(url)
            };

            request.Headers.Add("User-Agent", userAgent ?? "YubicoDotNetClient");

            try
            {
                var response = await _httpClient.SendAsync(request, token);

                token.ThrowIfCancellationRequested();
                if (!response.IsSuccessStatusCode)
                {
                    return(null);
                }

                IYubicoResponse yubiResponse;
                var             responseContent = await response.Content.ReadAsStringAsync();

                token.ThrowIfCancellationRequested();

                try
                {
                    yubiResponse = new YubicoResponse(responseContent, url);
                }
                catch (ArgumentException)
                {
                    return(null);
                }

                token.ThrowIfCancellationRequested();
                if (yubiResponse.Status == YubicoResponseStatus.ReplayedRequest)
                {
                    //throw new YubicoValidationException("Replayed request, this otp & nonce combination has been seen before.");
                    return(null);
                }

                return(yubiResponse);
            }
            catch (TaskCanceledException)
            {
                // timeout
                return(null);
            }
        }
Exemplo n.º 3
0
        private static IYubicoResponse DoVerify(string url, string userAgent)
        {
            var request = (HttpWebRequest)WebRequest.Create(url);

            if (userAgent == null)
            {
                request.UserAgent = "YubicoDotNetClient version:" + Assembly.GetExecutingAssembly().GetName().Version;
            }
            else
            {
                request.UserAgent = userAgent;
            }

            request.Timeout = 15000;

            HttpWebResponse rawResponse;
            try
            {
                rawResponse = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException)
            {
                return null;
            }

            using (var dataStream = rawResponse.GetResponseStream())
            {
                if (dataStream != null)
                {
                    using (var reader = new StreamReader(dataStream))
                    {
                        IYubicoResponse response;

                        try
                        {
                            response = new YubicoResponse(reader.ReadToEnd(), url);
                        }
                        catch (ArgumentException)
                        {
                            return null;
                        }

                        if (response.Status == YubicoResponseStatus.ReplayedRequest)
                        {
                            //throw new YubicoValidationException("Replayed request, this otp & nonce combination has been seen before.");
                            return null;
                        }

                        return response;
                    }
                }
            }

            throw new YubicoValidationException();
        }