Exemplo n.º 1
0
        public async Task CanOnlySignInIfSupported()
        {
            var services = new ServiceCollection().AddOptions().AddAuthenticationCore(o =>
            {
                o.AddScheme <UberHandler>("uber", "whatever");
                o.AddScheme <BaseHandler>("base", "whatever");
                o.AddScheme <SignInHandler>("signin", "whatever");
                o.AddScheme <SignOutHandler>("signout", "whatever");
            }).BuildServiceProvider();
            var context = new DefaultProtoContext();

            context.RequestServices = services;

            await context.SignInAsync("uber", new ClaimsPrincipal(), null);

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

            Assert.Contains("uber", ex.Message);
            Assert.Contains("signin", ex.Message);
            await context.SignInAsync("signin", new ClaimsPrincipal(), null);

            ex = await Assert.ThrowsAsync <InvalidOperationException>(() => context.SignInAsync("signout", new ClaimsPrincipal(), null));

            Assert.Contains("uber", ex.Message);
            Assert.Contains("signin", ex.Message);
        }
Exemplo 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());
        }
Exemplo 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);
        }