Beispiel #1
0
        public async Task CanOnlySignOutIfSupported()
        {
            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.SignOutAsync("uber");

            var ex = await Assert.ThrowsAsync <InvalidOperationException>(() => context.SignOutAsync("base"));

            Assert.Contains("uber", ex.Message);
            Assert.Contains("signout", ex.Message);
            await context.SignOutAsync("signout");

            await context.SignOutAsync("signin");
        }
Beispiel #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());
        }
Beispiel #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);
        }