public StubOwinMiddleware(
     int statusCode,
     AuthenticationResponseChallenge challenge = null,
     AuthenticationResponseRevoke revoke = null,
     AuthenticationResponseGrant grant = null)
      : base(null)
 {
     this.statusCode = statusCode;
     this.challenge = challenge;
     this.revoke = revoke;
     this.grant = grant;
 }
 private static AuthenticationResponseChallenge AddChallengeAuthenticationType(
     AuthenticationResponseChallenge challenge, string authenticationType)
 {
     List<string> list = new List<string>();
     AuthenticationProperties properties;
     if (challenge != null)
     {
         string[] authenticationTypes = challenge.AuthenticationTypes;
         if (authenticationTypes != null)
             list.AddRange((IEnumerable<string>) authenticationTypes);
         properties = challenge.Properties;
     }
     else
         properties = new AuthenticationProperties();
     list.Add(authenticationType);
     return new AuthenticationResponseChallenge(list.ToArray(), properties);
 }
 public void Challenge(AuthenticationProperties properties, params string[] authenticationTypes)
 {
     _context.Response.StatusCode    = 401;
     AuthenticationResponseChallenge = new AuthenticationResponseChallenge(authenticationTypes, properties);
 }
        private static AuthenticationResponseChallenge AddChallengeAuthenticationType(
            AuthenticationResponseChallenge challenge, string authenticationType)
        {
            Contract.Assert(authenticationType != null);

            List<string> authenticationTypes = new List<string>();
            AuthenticationExtra extra;

            if (challenge != null)
            {
                string[] currentAuthenticationTypes = challenge.AuthenticationTypes;

                if (currentAuthenticationTypes != null)
                {
                    authenticationTypes.AddRange(currentAuthenticationTypes);
                }

                extra = challenge.Extra;
            }
            else
            {
                extra = new AuthenticationExtra();
            }

            authenticationTypes.Add(authenticationType);

            return new AuthenticationResponseChallenge(authenticationTypes.ToArray(), extra);
        }
        public void Challenge(AuthenticationProperties properties, params string[] authenticationTypes)
        {
            _context.Response.StatusCode = 401;
            AuthenticationResponseChallenge priorChallenge = AuthenticationResponseChallenge;
            if (priorChallenge == null)
            {
                AuthenticationResponseChallenge = new AuthenticationResponseChallenge(authenticationTypes, properties);
            }
            else
            {
                // Cumulative auth types
                string[] mergedAuthTypes = priorChallenge.AuthenticationTypes.Concat(authenticationTypes).ToArray();

                if (properties != null)
                {
                    // Update prior properties
                    foreach (var propertiesPair in properties.Dictionary)
                    {
                        priorChallenge.Properties.Dictionary[propertiesPair.Key] = propertiesPair.Value;
                    }
                }

                AuthenticationResponseChallenge = new AuthenticationResponseChallenge(mergedAuthTypes, priorChallenge.Properties);
            }
        }
 private static IAuthenticationManager CreateAuthenticationManager(AuthenticationResponseChallenge challenge)
 {
     Mock<IAuthenticationManager> mock = new Mock<IAuthenticationManager>(MockBehavior.Strict);
     mock.SetupProperty(m => m.AuthenticationResponseChallenge);
     IAuthenticationManager authenticationManager = mock.Object;
     authenticationManager.AuthenticationResponseChallenge = challenge;
     return authenticationManager;
 }
        public void ChallengeAsync_CreatesAuthenticationTypes_WhenOwinChallengeWithNullTypesAlreadyExists()
        {
            // Arrange
            string expectedAuthenticationType = "AuthenticationType";
            IAuthenticationFilter filter = CreateProductUnderTest(expectedAuthenticationType);
            IHttpActionResult result = CreateDummyActionResult();
            AuthenticationProperties originalExtra = CreateExtra();
            AuthenticationResponseChallenge originalChallenge = new AuthenticationResponseChallenge(null,
                originalExtra);
            IAuthenticationManager authenticationManager = CreateAuthenticationManager(originalChallenge);
            IOwinContext owinContext = CreateOwinContext(authenticationManager);

            using (HttpRequestMessage request = CreateRequest(owinContext))
            {
                HttpAuthenticationChallengeContext context = CreateChallengeContext(request, result);

                // Act
                filter.ChallengeAsync(context, CancellationToken.None).Wait();
            }

            // Assert
            AuthenticationResponseChallenge challenge = authenticationManager.AuthenticationResponseChallenge;
            Assert.NotNull(challenge);
            string[] authenticationTypes = challenge.AuthenticationTypes;
            Assert.NotNull(authenticationTypes);
            Assert.Equal(1, authenticationTypes.Length);
            Assert.Same(expectedAuthenticationType, authenticationTypes[0]);
            AuthenticationProperties extra = challenge.Properties;
            Assert.Same(originalExtra, extra);
        }
 public StubOwinMiddleware(int statusCode, AuthenticationResponseChallenge challenge)
      : base(null)
 {
     this.statusCode = statusCode;
     this.challenge = challenge;
 }
예제 #9
0
 public void Challenge(string[] authenticationTypes, AuthenticationExtra extra)
 {
     StatusCode = 401;
     AuthenticationResponseChallenge = new AuthenticationResponseChallenge(authenticationTypes, extra);
 }
 public void Challenge(params string[] authenticationTypes)
 {
     StatusCode = 401;
     AuthenticationResponseChallenge = new AuthenticationResponseChallenge(
         authenticationTypes,
         new Dictionary<string, string>(StringComparer.Ordinal));
 }