Example #1
0
        public async Task ForbidThrowsForSchemeMismatch()
        {
            var services = new ServiceCollection().AddOptions().AddAuthenticationCore(o =>
            {
                o.AddScheme <BaseHandler>("base", "whatever");
            }).BuildServiceProvider();
            var context = new DefaultProtoContext();

            context.RequestServices = services;

            await context.ForbidAsync("base");

            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => context.ForbidAsync("missing"));

            Assert.Contains("base", ex.Message);
        }
Example #2
0
        public async Task ServicesWithDefaultForbidMethod_CallsForbidMethod()
        {
            var services = new ServiceCollection().AddOptions().AddAuthenticationCore(o =>
            {
                o.AddScheme <ForbidHandler>("forbid", "whatever");
                o.DefaultForbidScheme = "forbid";
            }).BuildServiceProvider();
            var context = new DefaultProtoContext();

            context.RequestServices = services;

            await context.ForbidAsync();
        }
Example #3
0
        public async Task ServicesWithDefaultSignInMethodsTest()
        {
            var services = new ServiceCollection().AddOptions().AddAuthenticationCore(o =>
            {
                o.AddScheme <SignInHandler>("base", "whatever");
                o.DefaultScheme = "base";
            }).BuildServiceProvider();
            var context = new DefaultProtoContext();

            context.RequestServices = services;

            await context.AuthenticateAsync();

            await context.ChallengeAsync();

            await context.ForbidAsync();

            await context.SignOutAsync();

            await context.SignInAsync(new ClaimsPrincipal());
        }
Example #4
0
        public async Task ServicesWithDefaultSignOutMethodsTest()
        {
            var services = new ServiceCollection().AddOptions().AddAuthenticationCore(o =>
            {
                o.AddScheme <SignOutHandler>("base", "whatever");
                o.DefaultScheme = "base";
            }).BuildServiceProvider();
            var context = new DefaultProtoContext();

            context.RequestServices = services;

            await context.AuthenticateAsync();

            await context.ChallengeAsync();

            await context.ForbidAsync();

            await context.SignOutAsync();

            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => context.SignInAsync(new ClaimsPrincipal()));

            Assert.Contains("cannot be used for SignInAsync", ex.Message);
        }