From 09078455db255c4ae99beaa84c17cd069fe70ca2 Mon Sep 17 00:00:00 2001 From: JudahGabriel Date: Fri, 9 Feb 2018 11:52:30 -0800 Subject: [PATCH] Upgraded to RavenDB 4.0. Added XML docs. --- RavenDB.Identity/IdentityRole.cs | 2 +- RavenDB.Identity/IdentityRoleClaim.cs | 2 +- RavenDB.Identity/IdentityUser.cs | 40 ++++++- RavenDB.Identity/RavenDB.Identity.csproj | 4 +- RavenDB.Identity/RoleStore.cs | 5 +- .../ServiceCollectionExtensions.cs | 112 +++++++----------- RavenDB.Identity/UserStore.cs | 83 ++++++++++--- RavenDB.Identity/Util.cs | 2 +- Sample/Controllers/AccountController.cs | 14 +-- Sample/Controllers/HomeController.cs | 14 +-- Sample/Controllers/RavenController.cs | 8 +- Sample/Models/AppUser.cs | 2 +- Sample/Startup.cs | 16 ++- 13 files changed, 189 insertions(+), 115 deletions(-) diff --git a/RavenDB.Identity/IdentityRole.cs b/RavenDB.Identity/IdentityRole.cs index 0d6ffc4..056f0d2 100644 --- a/RavenDB.Identity/IdentityRole.cs +++ b/RavenDB.Identity/IdentityRole.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace RavenDB.Identity +namespace Raven.Identity { /// /// The default implementation of which uses a string as the primary key. diff --git a/RavenDB.Identity/IdentityRoleClaim.cs b/RavenDB.Identity/IdentityRoleClaim.cs index 0296665..6920b54 100644 --- a/RavenDB.Identity/IdentityRoleClaim.cs +++ b/RavenDB.Identity/IdentityRoleClaim.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Security.Claims; using System.Text; -namespace RavenDB.Identity +namespace Raven.Identity { /// /// Represents a claim that is granted to all users within a role. diff --git a/RavenDB.Identity/IdentityUser.cs b/RavenDB.Identity/IdentityUser.cs index 08ab116..1c3d044 100644 --- a/RavenDB.Identity/IdentityUser.cs +++ b/RavenDB.Identity/IdentityUser.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; -namespace RavenDB.Identity +namespace Raven.Identity { /// /// Base user class for RavenDB Identity. Inherit from this class to add your own properties. @@ -107,25 +107,63 @@ namespace RavenDB.Identity } } + /// + /// Defines a user login. + /// public sealed class IdentityUserLogin { + /// + /// The ID of the login. + /// public string Id { get; set; } + /// + /// The user ID. + /// public string UserId { get; set; } + /// + /// The login provider. + /// public string Provider { get; set; } + /// + /// The login provider key. + /// public string ProviderKey { get; set; } } + /// + /// A login claim. + /// public class IdentityUserClaim { + /// + /// The type of the login claim. + /// public virtual string ClaimType { get; set; } + /// + /// The login claim value. + /// public virtual string ClaimValue { get; set; } } + /// + /// Entity that aides in helping us load users by a well-known name directly from the RavenDB ACID storage engine, bypassing the eventually consistent RavenDB indexes. + /// public sealed class IdentityUserByUserName { + /// + /// The ID of the user. + /// public string UserId { get; set; } + /// + /// The user name. + /// public string UserName { get; set; } + /// + /// Creates a new IdentityUserByUserName. + /// + /// + /// public IdentityUserByUserName(string userId, string userName) { UserId = userId; diff --git a/RavenDB.Identity/RavenDB.Identity.csproj b/RavenDB.Identity/RavenDB.Identity.csproj index a061152..8067148 100644 --- a/RavenDB.Identity/RavenDB.Identity.csproj +++ b/RavenDB.Identity/RavenDB.Identity.csproj @@ -23,9 +23,9 @@ - + - + diff --git a/RavenDB.Identity/RoleStore.cs b/RavenDB.Identity/RoleStore.cs index 73b4a5c..0711fbc 100644 --- a/RavenDB.Identity/RoleStore.cs +++ b/RavenDB.Identity/RoleStore.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Identity; -using Raven.Abstractions.Exceptions; using Raven.Client; using System; using System.Collections.Generic; @@ -10,8 +9,10 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; +using Raven.Client.Documents.Session; +using Raven.Client.Exceptions; -namespace RavenDB.Identity +namespace Raven.Identity { /// /// diff --git a/RavenDB.Identity/ServiceCollectionExtensions.cs b/RavenDB.Identity/ServiceCollectionExtensions.cs index 88938e3..602d691 100644 --- a/RavenDB.Identity/ServiceCollectionExtensions.cs +++ b/RavenDB.Identity/ServiceCollectionExtensions.cs @@ -1,81 +1,17 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Raven.Client; -using Raven.Client.Document; +using Raven.Client.Documents; +using Raven.Client.Documents.Session; using System; -namespace RavenDB.Identity +namespace Raven.Identity { /// /// Extends the so that RavenDB services can be registered through it. /// public static class ServiceCollectionExtensions { - /// - /// Registers a RavenDB as a singleton. - /// - /// - /// - /// public void ConfigureServices(IServiceCollection services) - /// { - /// services.AddRavenDb(Configuration.GetConnectionString("RavenDbConnection"))); - /// } - /// - /// - /// The to add services to. - /// The connection string to the Raven database instance. - /// An optional action to configure the . - /// Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs - /// - /// The same service collection so that multiple calls can be chained. - /// - public static IServiceCollection AddRavenDb( - this IServiceCollection serviceCollection, - string connectionString, - Action configureAction = null) - { - if (string.IsNullOrEmpty(connectionString)) - { - throw new ArgumentNullException("Connection string cannot be null or empty."); - } - - var documentStore = new DocumentStore(); - documentStore.ParseConnectionString(connectionString); - documentStore.Conventions.RegisterIdConvention((dbname, commands, user) => "IdentityUsers/" + user.Id); - configureAction?.Invoke(documentStore); - documentStore.Initialize(); - - serviceCollection.AddSingleton(documentStore); - - return serviceCollection; - } - - /// - /// Registers a RavenDB to be created and disposed on each request. - /// - /// - /// - /// public void ConfigureServices(IServiceCollection services) - /// { - /// services.AddRavenDbAsyncSession(); - /// } - /// - /// - /// The to add services to. - /// Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs - /// The same service collection so that multiple calls can be chained. - public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection) - { - var docStore = serviceCollection.BuildServiceProvider().GetService(); - if (docStore == null) - { - throw new InvalidOperationException($"Please call {nameof(AddRavenDb)} before calling {nameof(AddRavenDbAsyncSession)}."); - } - - serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => docStore.OpenAsyncSession(), ServiceLifetime.Scoped)); - return serviceCollection; - } - /// /// Registers a RavenDB as the user store. /// @@ -103,5 +39,47 @@ namespace RavenDB.Identity return services; } + + /// + /// Registers a RavenDB to be created and disposed on each request. + /// + /// + /// + /// public void ConfigureServices(IServiceCollection services) + /// { + /// services.AddRavenDbAsyncSession(() => myRavenDocStore); + /// } + /// + /// + /// The to add services to. + /// The function that gets the database. + /// Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs + /// The same service collection so that multiple calls can be chained. + public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, Func dbGetter) + { + serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => dbGetter().OpenAsyncSession(), ServiceLifetime.Scoped)); + return serviceCollection; + } + + /// + /// Registers a RavenDB to be created and disposed on each request. + /// + /// + /// + /// public void ConfigureServices(IServiceCollection services) + /// { + /// services.AddRavenDbAsyncSession(() => myRavenDocStore); + /// } + /// + /// + /// The to add services to. + /// The RavenDB document store. + /// Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs + /// The same service collection so that multiple calls can be chained. + public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, IDocumentStore db) + { + serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => db.OpenAsyncSession(), ServiceLifetime.Scoped)); + return serviceCollection; + } } } diff --git a/RavenDB.Identity/UserStore.cs b/RavenDB.Identity/UserStore.cs index 8b688ea..e9843d6 100644 --- a/RavenDB.Identity/UserStore.cs +++ b/RavenDB.Identity/UserStore.cs @@ -1,17 +1,14 @@ -using System; -using System.Collections; +using Microsoft.AspNetCore.Identity; +using Raven.Client.Documents; +using Raven.Client.Documents.Session; +using System; using System.Collections.Generic; using System.Linq; using System.Security.Claims; -using System.Security.Cryptography; -using System.Text; using System.Threading; using System.Threading.Tasks; -using Microsoft.AspNetCore.Identity; -using Raven.Client; -using System.Runtime.CompilerServices; -namespace RavenDB.Identity +namespace Raven.Identity { /// /// UserStore for entities in a RavenDB database. @@ -34,11 +31,13 @@ namespace RavenDB.Identity private readonly Func getSessionFunc; private IAsyncDocumentSession _session; + /// public UserStore(Func getSession) { this.getSessionFunc = getSession; } + /// public UserStore(IAsyncDocumentSession session) { this._session = session; @@ -46,6 +45,7 @@ namespace RavenDB.Identity #region IDispoable implementation + /// public void Dispose() { _disposed = true; @@ -55,6 +55,7 @@ namespace RavenDB.Identity #region IUserStore implementation + /// public Task GetUserIdAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -62,6 +63,7 @@ namespace RavenDB.Identity return Task.FromResult(user.Id); } + /// public Task GetUserNameAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -69,6 +71,7 @@ namespace RavenDB.Identity return Task.FromResult(user.UserName); } + /// public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -77,6 +80,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetNormalizedUserNameAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -85,6 +89,7 @@ namespace RavenDB.Identity return Task.FromResult(user.UserName); } + /// public Task SetNormalizedUserNameAsync(TUser user, string normalizedName, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -93,13 +98,19 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// + /// Creates a user asynchronously. + /// + /// + /// + /// public async Task CreateAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); if (string.IsNullOrEmpty(user.Id)) { var conventions = DbSession.Advanced.DocumentStore.Conventions; - var entityName = conventions.GetTypeTagName(typeof(TUser)); + var entityName = conventions.GetCollectionName(typeof(TUser)); var separator = conventions.IdentityPartsSeparator; var id = $"{entityName}{separator}{user.Email}"; user.Id = id; @@ -115,6 +126,7 @@ namespace RavenDB.Identity return IdentityResult.Success; } + /// public Task UpdateAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -122,6 +134,7 @@ namespace RavenDB.Identity return Task.FromResult(IdentityResult.Success); } + /// public async Task DeleteAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -138,6 +151,7 @@ namespace RavenDB.Identity return IdentityResult.Success; } + /// public Task FindByIdAsync(string userId, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); @@ -145,6 +159,7 @@ namespace RavenDB.Identity return DbSession.LoadAsync(userId); } + /// public async Task FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); @@ -168,6 +183,7 @@ namespace RavenDB.Identity #region IUserLoginStore implementation + /// public async Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -191,6 +207,7 @@ namespace RavenDB.Identity } } + /// public async Task RemoveLoginAsync(TUser user, string loginProvider, string providerKey, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -208,6 +225,7 @@ namespace RavenDB.Identity user.Logins.RemoveAll(x => x.LoginProvider == login.LoginProvider && x.ProviderKey == login.ProviderKey); } + /// public Task> GetLoginsAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -215,6 +233,7 @@ namespace RavenDB.Identity return Task.FromResult(user.Logins.ToIList()); } + /// public async Task FindByLoginAsync(string loginProvider, string providerKey, CancellationToken cancellationToken) { var login = new UserLoginInfo(loginProvider, providerKey, string.Empty); @@ -232,6 +251,7 @@ namespace RavenDB.Identity #region IUserClaimStore implementation + /// public Task> GetClaimsAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -242,6 +262,7 @@ namespace RavenDB.Identity return Task.FromResult(result); } + /// public Task AddClaimsAsync(TUser user, IEnumerable claims, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -250,6 +271,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public async Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -262,6 +284,7 @@ namespace RavenDB.Identity } } + /// public Task RemoveClaimsAsync(TUser user, IEnumerable claims, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -270,7 +293,8 @@ namespace RavenDB.Identity return Task.CompletedTask; } - public Task> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken) + /// + public async Task> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); if (claim == null) @@ -278,9 +302,10 @@ namespace RavenDB.Identity throw new ArgumentNullException(nameof(claim)); } - return DbSession.Query() + var list = await DbSession.Query() .Where(u => u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value)) .ToListAsync(); + return list; } #endregion @@ -341,6 +366,7 @@ namespace RavenDB.Identity } } + /// public Task> GetRolesAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -348,6 +374,7 @@ namespace RavenDB.Identity return Task.FromResult>(new List(user.Roles)); } + /// public Task IsInRoleAsync(TUser user, string roleName, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(roleName)) @@ -358,7 +385,8 @@ namespace RavenDB.Identity return Task.FromResult(user.Roles.Contains(roleName, StringComparer.OrdinalIgnoreCase)); } - public Task> GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken) + /// + public async Task> GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); if (string.IsNullOrEmpty(roleName)) @@ -366,16 +394,18 @@ namespace RavenDB.Identity throw new ArgumentNullException(nameof(roleName)); } - return DbSession.Query() + var users = await DbSession.Query() .Where(u => u.Roles.Contains(roleName, StringComparer.InvariantCultureIgnoreCase)) .Take(1024) .ToListAsync(); + return users; } #endregion #region IUserPasswordStore implementation + /// public Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -384,6 +414,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetPasswordHashAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -391,6 +422,7 @@ namespace RavenDB.Identity return Task.FromResult(user.PasswordHash); } + /// public Task HasPasswordAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -402,6 +434,7 @@ namespace RavenDB.Identity #region IUserSecurityStampStore implementation + /// public Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -410,6 +443,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetSecurityStampAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -421,6 +455,7 @@ namespace RavenDB.Identity #region IUserEmailStore implementation + /// public Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); @@ -428,6 +463,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetEmailAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -435,6 +471,7 @@ namespace RavenDB.Identity return Task.FromResult(user.Email); } + /// public Task GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -442,6 +479,7 @@ namespace RavenDB.Identity return Task.FromResult(user.EmailConfirmed); } + /// public Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -450,6 +488,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken) { ThrowIfDisposedOrCancelled(cancellationToken); @@ -458,6 +497,7 @@ namespace RavenDB.Identity .FirstOrDefaultAsync(u => u.Email == normalizedEmail, cancellationToken); } + /// public Task GetNormalizedEmailAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -466,6 +506,7 @@ namespace RavenDB.Identity return Task.FromResult(user.Email); } + /// public Task SetNormalizedEmailAsync(TUser user, string normalizedEmail, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -482,6 +523,7 @@ namespace RavenDB.Identity #region IUserLockoutStore implementation + /// public Task GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -489,6 +531,7 @@ namespace RavenDB.Identity return Task.FromResult(user.LockoutEndDate); } + /// public Task SetLockoutEndDateAsync(TUser user, DateTimeOffset? lockoutEnd, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -497,6 +540,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -505,6 +549,7 @@ namespace RavenDB.Identity return Task.FromResult(user.AccessFailedCount); } + /// public Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -513,6 +558,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -520,12 +566,14 @@ namespace RavenDB.Identity return Task.FromResult(user.AccessFailedCount); } + /// public Task GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); return Task.FromResult(user.LockoutEnabled); } + /// public Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -538,6 +586,7 @@ namespace RavenDB.Identity #region IUserTwoFactorStore implementation + /// public Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -546,6 +595,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -557,6 +607,7 @@ namespace RavenDB.Identity #region IUserPhoneNumberStore implementation + /// public Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -565,6 +616,7 @@ namespace RavenDB.Identity return Task.CompletedTask; } + /// public Task GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -572,6 +624,7 @@ namespace RavenDB.Identity return Task.FromResult(user.PhoneNumber); } + /// public Task GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -579,6 +632,7 @@ namespace RavenDB.Identity return Task.FromResult(user.IsPhoneNumberConfirmed); } + /// public Task SetPhoneNumberConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken) { ThrowIfNullDisposedCancelled(user, cancellationToken); @@ -596,7 +650,8 @@ namespace RavenDB.Identity if (_session == null) { _session = getSessionFunc(); - _session.Advanced.DocumentStore.Conventions.RegisterIdConvention((dbname, commands, user) => "IdentityUsers/" + user.Id); + // TODO: do we really need this? I don't believe so. Brought over from Raven 3.x - the new 4.0 uses async version only. + //_session.Advanced.DocumentStore.Conventions.RegisterIdConvention((dbname, commands, user) => "IdentityUsers/" + user.Id); } return _session; } diff --git a/RavenDB.Identity/Util.cs b/RavenDB.Identity/Util.cs index 934e022..edeb375 100644 --- a/RavenDB.Identity/Util.cs +++ b/RavenDB.Identity/Util.cs @@ -5,7 +5,7 @@ using System.Security.Cryptography; using System.Text; using Microsoft.AspNetCore.Identity; -namespace RavenDB.Identity +namespace Raven.Identity { internal static class Util { diff --git a/Sample/Controllers/AccountController.cs b/Sample/Controllers/AccountController.cs index 5291562..eed110f 100644 --- a/Sample/Controllers/AccountController.cs +++ b/Sample/Controllers/AccountController.cs @@ -1,19 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Claims; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; +using Raven.Client.Documents.Session; using Sample.Models; using Sample.Models.AccountViewModels; using Sample.Services; -using Raven.Client; +using System; +using System.Security.Claims; +using System.Threading.Tasks; namespace Sample.Controllers { diff --git a/Sample/Controllers/HomeController.cs b/Sample/Controllers/HomeController.cs index d1f544f..87e74d1 100644 --- a/Sample/Controllers/HomeController.cs +++ b/Sample/Controllers/HomeController.cs @@ -1,13 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; +using Raven.Client.Documents; +using Raven.Client.Documents.Session; +using Sample.Models; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Sample.Models; -using Raven.Client; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Identity; namespace Sample.Controllers { diff --git a/Sample/Controllers/RavenController.cs b/Sample/Controllers/RavenController.cs index 5b95909..662d38e 100644 --- a/Sample/Controllers/RavenController.cs +++ b/Sample/Controllers/RavenController.cs @@ -1,10 +1,8 @@ using Microsoft.AspNetCore.Mvc; -using Raven.Client; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Filters; +using Raven.Client.Documents.Session; +using System; +using System.Threading.Tasks; namespace Sample.Controllers { diff --git a/Sample/Models/AppUser.cs b/Sample/Models/AppUser.cs index 0824bad..6d2f14d 100644 --- a/Sample/Models/AppUser.cs +++ b/Sample/Models/AppUser.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using RavenDB.Identity; +using Raven.Identity; namespace Sample.Models { diff --git a/Sample/Startup.cs b/Sample/Startup.cs index f5dc2ee..53a64fd 100644 --- a/Sample/Startup.cs +++ b/Sample/Startup.cs @@ -10,7 +10,8 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Sample.Models; using Sample.Services; -using RavenDB.Identity; +using Raven.Identity; +using Raven.Client.Documents; namespace Sample { @@ -26,10 +27,19 @@ namespace Sample // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { + + // Connect to a Raven server. We're using the public test playground at http://live-test.ravendb.net + // NOTE: Getting a DatabaseDoesNotExistException? Go to http://live-test.ravendb.net and create a database with the name 'Raven.Identity.Sample' + var docStore = new DocumentStore + { + Urls = new string[] { "http://live-test.ravendb.net" }, + Database = "Raven.Identity.Sample" + }; + docStore.Initialize(); + // Add RavenDB and identity. services - .AddRavenDb(Configuration.GetConnectionString("RavenDbConnection")) // Create a RavenDB DocumentStore singleton. - .AddRavenDbAsyncSession() // Create a RavenDB IAsyncDocumentSession for each request. + .AddRavenDbAsyncSession(docStore) // Create a RavenDB IAsyncDocumentSession for each request. .AddRavenDbIdentity(); // Use Raven for users and roles. // You can change the login path if need be.