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

            context.RequestServices = services;

            await context.AuthenticateAsync("base");

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

            Assert.Contains("base", ex.Message);
        }
Esempio n. 2
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());
        }
Esempio n. 3
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);
        }