Пример #1
0
        internal static (string value, OpenIdConnectMessage error) ValidateParameterIsUnique(
            IDictionary <string, string[]> requestParameters,
            string parameterName,
            ProtocolErrorProvider provider)
        {
            if (requestParameters.TryGetValue(parameterName, out var currentParameter))
            {
                if (currentParameter.Length > 1)
                {
                    return(null, provider.TooManyParameters(parameterName));
                }

                var parameterValue = currentParameter.SingleOrDefault();
                if (string.IsNullOrEmpty(parameterValue))
                {
                    return(null, provider.MissingRequiredParameter(parameterName));
                }

                return(parameterValue, null);
            }
            else
            {
                return(null, provider.MissingRequiredParameter(parameterName));
            }
        }
Пример #2
0
        public async Task FailsToCreateAuthorizationRequest_IfState_HasMultipleValues()
        {
            // Arrange
            var parameters = new Dictionary <string, string[]>
            {
                [OpenIdConnectParameterNames.State] = new[] { "a", "b" }
            };
            var expectedError = new AuthorizationRequestError(ProtocolErrorProvider.TooManyParameters(OpenIdConnectParameterNames.State), null, null);
            var factory       = CreateAuthorizationRequestFactory();

            // Act
            var result = await factory.CreateAuthorizationRequestAsync(parameters);

            // Assert
            Assert.False(result.IsValid);
            Assert.Equal(expectedError, result.Error, IdentityServiceErrorComparer.Instance);
            Assert.Null(result.Error.RedirectUri);
            Assert.Null(result.Error.ResponseMode);
        }
Пример #3
0
        internal static (string value, OpenIdConnectMessage error) ValidateOptionalParameterIsUnique(
            IDictionary <string, string[]> requestParameters,
            string parameterName, ProtocolErrorProvider provider)
        {
            if (requestParameters.TryGetValue(parameterName, out var currentParameter))
            {
                if (currentParameter.Count() != 1)
                {
                    return(null, provider.TooManyParameters(parameterName));
                }

                return(currentParameter.Single(), null);
            }

            return(null, null);
        }