예제 #1
0
        public void AuthenticateContext_NotAuthenticated()
        {
            // Arrange
            var context = new AuthenticateContext("test");

            // Act
            context.NotAuthenticated();

            // Assert
            Assert.True(context.Accepted);
            Assert.Equal("test", context.AuthenticationScheme);
            Assert.Null(context.Description);
            Assert.Null(context.Error);
            Assert.Null(context.Principal);
            Assert.Null(context.Properties);
        }
예제 #2
0
        public void AuthenticateContext_NotAuthenticated_SetsUnusedPropertiesToDefault_Failed()
        {
            // Arrange
            var context = new AuthenticateContext("test");

            context.Failed(new Exception());

            context.NotAuthenticated();

            // Assert
            Assert.True(context.Accepted);
            Assert.Equal("test", context.AuthenticationScheme);
            Assert.Null(context.Description);
            Assert.Null(context.Error);
            Assert.Null(context.Principal);
            Assert.Null(context.Properties);
        }
예제 #3
0
        public void AuthenticateContext_NotAuthenticated_SetsUnusedPropertiesToDefault_Authenticated()
        {
            // Arrange
            var context = new AuthenticateContext("test");

            var exception = new Exception();

            context.Authenticated(new ClaimsPrincipal(), new Dictionary <string, string>(), new Dictionary <string, object>());

            // Act
            context.NotAuthenticated();

            // Assert
            Assert.True(context.Accepted);
            Assert.Equal("test", context.AuthenticationScheme);
            Assert.Null(context.Description);
            Assert.Null(context.Error);
            Assert.Null(context.Principal);
            Assert.Null(context.Properties);
        }
        public Task AuthenticateAsync(AuthenticateContext context)
        {
            if (ShouldHandleScheme(context.AuthenticationScheme))
            {
                if (User != null)
                {
                    context.Authenticated(User, properties: null,
                        description: Options.AuthenticationDescriptions.FirstOrDefault(descrip =>
                            string.Equals(User.Identity.AuthenticationType, descrip.AuthenticationScheme, StringComparison.Ordinal))?.Items);
                }
                else
                {
                    context.NotAuthenticated();
                }
            }

            if (PriorHandler != null)
            {
                return PriorHandler.AuthenticateAsync(context);
            }

            return Task.FromResult(0);
        }
        public void AuthenticateContext_NotAuthenticated_SetsUnusedPropertiesToDefault_Failed()
        {
            // Arrange
            var context = new AuthenticateContext("test");
            
            context.Failed(new Exception());

            context.NotAuthenticated();

            // Assert
            Assert.True(context.Accepted);
            Assert.Equal("test", context.AuthenticationScheme);
            Assert.Null(context.Description);
            Assert.Null(context.Error);
            Assert.Null(context.Principal);
            Assert.Null(context.Properties);
        }
        public void AuthenticateContext_NotAuthenticated_SetsUnusedPropertiesToDefault_Authenticated()
        {
            // Arrange
            var context = new AuthenticateContext("test");

            var exception = new Exception();

            context.Authenticated(new ClaimsPrincipal(), new Dictionary<string, string>(), new Dictionary<string, object>());

            // Act
            context.NotAuthenticated();

            // Assert
            Assert.True(context.Accepted);
            Assert.Equal("test", context.AuthenticationScheme);
            Assert.Null(context.Description);
            Assert.Null(context.Error);
            Assert.Null(context.Principal);
            Assert.Null(context.Properties);
        }
        public void AuthenticateContext_NotAuthenticated()
        {
            // Arrange
            var context = new AuthenticateContext("test");

            // Act
            context.NotAuthenticated();

            // Assert
            Assert.True(context.Accepted);
            Assert.Equal("test", context.AuthenticationScheme);
            Assert.Null(context.Description);
            Assert.Null(context.Error);
            Assert.Null(context.Principal);
            Assert.Null(context.Properties);
        }
예제 #8
0
 public Task AuthenticateAsync(AuthenticateContext context)
 {
     context.NotAuthenticated();
     return Task.FromResult(0);
 }
예제 #9
0
 public void Authenticate(AuthenticateContext context)
 {
     context.NotAuthenticated();
 }