Exemplo n.º 1
0
        public async Task GetAsync_by_id_should_return_token()
        {
            var provider = new ServiceCollection()
                           .AddLogging()
                           .AddDbContext <IdentityDbContext <IdentityUser> >(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString()))
                           .AddIdentity <IdentityUser, IdentityRole>()
                           .AddEntityFrameworkStores <IdentityDbContext <IdentityUser> >()
                           .Services.BuildServiceProvider();

            var userManager = provider.GetRequiredService <UserManager <IdentityUser> >();
            var context     = provider.GetRequiredService <IdentityDbContext <IdentityUser> >();

            var id = Guid.NewGuid().ToString();
            await userManager.CreateAsync(new IdentityUser
            {
                Email    = "*****@*****.**",
                Id       = id,
                UserName = id
            }).ConfigureAwait(false);

            var sut = new IdentityUserTokenStore <IdentityUser>(userManager, context, provider.GetRequiredService <ILogger <IdentityUserTokenStore <IdentityUser> > >());

            await sut.CreateAsync(new UserToken
            {
                UserId        = id,
                LoginProvider = id,
                Name          = id,
                Value         = id
            } as object).ConfigureAwait(false);


            var result = await sut.GetAsync($"{id}@{id}@{id}", null).ConfigureAwait(false);

            Assert.NotNull(result);

            result = await sut.GetAsync($"{Guid.NewGuid()}@{id}@{id}", null).ConfigureAwait(false);

            Assert.Null(result);
        }
Exemplo n.º 2
0
        public async Task GetAsync_by_page_request_should_find_user_tokens()
        {
            using var documentStore = new RavenDbTestDriverWrapper().GetDocumentStore();
            var services = new ServiceCollection()
                           .AddLogging();

            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddRavenDbStores(p => documentStore);

            IServiceProvider provider = services.AddIdentityServer4AdminRavenDbkStores <IdentityUser, IdentityRole>(p => documentStore).BuildServiceProvider();

            using var scope = provider.CreateScope();
            provider        = scope.ServiceProvider;

            var userManager = provider.GetRequiredService <UserManager <IdentityUser> >();

            var user = new IdentityUser
            {
                Id             = Guid.NewGuid().ToString(),
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                UserName       = Guid.NewGuid().ToString()
            };
            var userResult = await userManager.CreateAsync(user);

            Assert.True(userResult.Succeeded);

            var loginProvder = Guid.NewGuid().ToString();

            await userManager.SetAuthenticationTokenAsync(user, loginProvder, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            await userManager.SetAuthenticationTokenAsync(user, loginProvder, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            await userManager.SetAuthenticationTokenAsync(user, loginProvder, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());

            var sut = new IdentityUserTokenStore <IdentityUser>(userManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityUserTokenStore <IdentityUser> > >());

            var result = await sut.GetAsync(new PageRequest
            {
                Filter = $"UserId eq '{user.Id}'",
                Take   = 1
            });

            Assert.NotNull(result);
            Assert.Equal(3, result.Count);
            Assert.Single(result.Items);
        }
Exemplo n.º 3
0
        public async Task GetAsync_by_id_should_return_token()
        {
            using var documentStore = new RavenDbTestDriverWrapper().GetDocumentStore();
            var services = new ServiceCollection()
                           .AddLogging();

            services.AddIdentity <IdentityUser, IdentityRole>()
            .AddRavenDbStores(p => documentStore);

            IServiceProvider provider = services.AddIdentityServer4AdminRavenDbkStores <IdentityUser, IdentityRole>(p => documentStore).BuildServiceProvider();

            using var scope = provider.CreateScope();
            provider        = scope.ServiceProvider;

            var userManager = provider.GetRequiredService <UserManager <IdentityUser> >();
            var user        = new IdentityUser
            {
                Id             = Guid.NewGuid().ToString(),
                Email          = "*****@*****.**",
                EmailConfirmed = true,
                UserName       = Guid.NewGuid().ToString()
            };
            var userResult = await userManager.CreateAsync(user);

            Assert.True(userResult.Succeeded);

            var loginProvder = Guid.NewGuid().ToString();
            var key          = Guid.NewGuid().ToString();

            await userManager.SetAuthenticationTokenAsync(user, loginProvder, key, Guid.NewGuid().ToString());

            var sut = new IdentityUserTokenStore <IdentityUser>(userManager, new ScopedAsynDocumentcSession(documentStore.OpenAsyncSession()), provider.GetRequiredService <ILogger <IdentityUserTokenStore <IdentityUser> > >());

            var result = await sut.GetAsync($"{user.Id}@{loginProvder}@{key}", null);

            Assert.NotNull(result);
        }