Ejemplo n.º 1
0
        public void PropertyGetter_ReturnsExpectedParameter(string property, string name, OpenIddictParameter value)
        {
            // Arrange
            var response = new OpenIddictResponse();
            response.SetParameter(name, value);

            // Act and assert
            Assert.Equal(value.Value, typeof(OpenIddictResponse).GetProperty(property)!.GetValue(response));
        }
        public void PropertySetter_AddsExpectedParameter(string property, string name, OpenIddictParameter value)
        {
            // Arrange
            var response = new OpenIddictResponse();

            // Act
            typeof(OpenIddictResponse).GetProperty(property).SetValue(response, value.Value);

            // Assert
            Assert.Equal(value, response.GetParameter(name));
        }
        private async Task <OpenIddictResponse> GetResponseAsync(HttpResponseMessage message)
        {
            if (message.Headers.WwwAuthenticate.Count != 0)
            {
                var response = new OpenIddictResponse();

                foreach (var header in message.Headers.WwwAuthenticate)
                {
                    if (string.IsNullOrEmpty(header.Parameter))
                    {
                        continue;
                    }

                    foreach (var parameter in header.Parameter.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        var values = parameter.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        if (values.Length != 2)
                        {
                            continue;
                        }

                        var name = values[0]?.Trim(' ', '"');
                        if (string.IsNullOrEmpty(name))
                        {
                            continue;
                        }

                        var value = values[1]?.Trim(' ', '"');
                        if (string.IsNullOrEmpty(name))
                        {
                            continue;
                        }

                        response.SetParameter(name, value);
                    }
                }

                return(response);
            }

            else if (message.Headers.Location != null)
            {
                var payload = message.Headers.Location.Fragment;
                if (string.IsNullOrEmpty(payload))
                {
                    payload = message.Headers.Location.Query;
                }

                if (string.IsNullOrEmpty(payload))
                {
                    return(new OpenIddictResponse());
                }