Upgraded to RavenDB 4.0. Added XML docs.

This commit is contained in:
JudahGabriel
2018-02-09 11:52:30 -08:00
parent 1f5ee40119
commit 09078455db
13 changed files with 189 additions and 115 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Text;
namespace RavenDB.Identity
namespace Raven.Identity
{
/// <summary>
/// The default implementation of <see cref="IdentityRole"/> which uses a string as the primary key.
+1 -1
View File
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Security.Claims;
using System.Text;
namespace RavenDB.Identity
namespace Raven.Identity
{
/// <summary>
/// Represents a claim that is granted to all users within a role.
+39 -1
View File
@@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
namespace RavenDB.Identity
namespace Raven.Identity
{
/// <summary>
/// Base user class for RavenDB Identity. Inherit from this class to add your own properties.
@@ -107,25 +107,63 @@ namespace RavenDB.Identity
}
}
/// <summary>
/// Defines a user login.
/// </summary>
public sealed class IdentityUserLogin
{
/// <summary>
/// The ID of the login.
/// </summary>
public string Id { get; set; }
/// <summary>
/// The user ID.
/// </summary>
public string UserId { get; set; }
/// <summary>
/// The login provider.
/// </summary>
public string Provider { get; set; }
/// <summary>
/// The login provider key.
/// </summary>
public string ProviderKey { get; set; }
}
/// <summary>
/// A login claim.
/// </summary>
public class IdentityUserClaim
{
/// <summary>
/// The type of the login claim.
/// </summary>
public virtual string ClaimType { get; set; }
/// <summary>
/// The login claim value.
/// </summary>
public virtual string ClaimValue { get; set; }
}
/// <summary>
/// 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.
/// </summary>
public sealed class IdentityUserByUserName
{
/// <summary>
/// The ID of the user.
/// </summary>
public string UserId { get; set; }
/// <summary>
/// The user name.
/// </summary>
public string UserName { get; set; }
/// <summary>
/// Creates a new IdentityUserByUserName.
/// </summary>
/// <param name="userId"></param>
/// <param name="userName"></param>
public IdentityUserByUserName(string userId, string userName)
{
UserId = userId;
+2 -2
View File
@@ -23,9 +23,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="RavenDB.Client" Version="3.5.5-patch-35218" />
<PackageReference Include="RavenDB.Client" Version="4.0.0" />
</ItemGroup>
</Project>
+3 -2
View File
@@ -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
{
/// <summary>
///
+45 -67
View File
@@ -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
{
/// <summary>
/// Extends the <see cref="IServiceCollection"/> so that RavenDB services can be registered through it.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Registers a RavenDB <see cref="DocumentStore"/> as a singleton.
/// </summary>
/// <example>
/// <code>
/// public void ConfigureServices(IServiceCollection services)
/// {
/// services.AddRavenDb(Configuration.GetConnectionString("RavenDbConnection")));
/// }
/// </code>
/// </example>
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <param name="connectionString"> The connection string to the Raven database instance. </param>
/// <param name="configureAction">An optional action to configure the <see cref="IDocumentStore" />.</param>
/// <remarks>Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs</remarks>
/// <returns>
/// The same service collection so that multiple calls can be chained.
/// </returns>
public static IServiceCollection AddRavenDb(
this IServiceCollection serviceCollection,
string connectionString,
Action<IDocumentStore> 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<IdentityUser>((dbname, commands, user) => "IdentityUsers/" + user.Id);
configureAction?.Invoke(documentStore);
documentStore.Initialize();
serviceCollection.AddSingleton<IDocumentStore>(documentStore);
return serviceCollection;
}
/// <summary>
/// Registers a RavenDB <see cref="IAsyncDocumentSession"/> to be created and disposed on each request.
/// </summary>
/// <example>
/// <code>
/// public void ConfigureServices(IServiceCollection services)
/// {
/// services.AddRavenDbAsyncSession();
/// }
/// </code>
/// </example>
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <remarks>Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs</remarks>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection)
{
var docStore = serviceCollection.BuildServiceProvider().GetService<IDocumentStore>();
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;
}
/// <summary>
/// Registers a RavenDB as the user store.
/// </summary>
@@ -103,5 +39,47 @@ namespace RavenDB.Identity
return services;
}
/// <summary>
/// Registers a RavenDB <see cref="IAsyncDocumentSession"/> to be created and disposed on each request.
/// </summary>
/// <example>
/// <code>
/// public void ConfigureServices(IServiceCollection services)
/// {
/// services.AddRavenDbAsyncSession(() => myRavenDocStore);
/// }
/// </code>
/// </example>
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <param name="dbGetter">The function that gets the database.</param>
/// <remarks>Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs</remarks>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, Func<IDocumentStore> dbGetter)
{
serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => dbGetter().OpenAsyncSession(), ServiceLifetime.Scoped));
return serviceCollection;
}
/// <summary>
/// Registers a RavenDB <see cref="IAsyncDocumentSession"/> to be created and disposed on each request.
/// </summary>
/// <example>
/// <code>
/// public void ConfigureServices(IServiceCollection services)
/// {
/// services.AddRavenDbAsyncSession(() => myRavenDocStore);
/// }
/// </code>
/// </example>
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <param name="db">The RavenDB document store.</param>
/// <remarks>Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs</remarks>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, IDocumentStore db)
{
serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => db.OpenAsyncSession(), ServiceLifetime.Scoped));
return serviceCollection;
}
}
}
+69 -14
View File
@@ -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
{
/// <summary>
/// UserStore for entities in a RavenDB database.
@@ -34,11 +31,13 @@ namespace RavenDB.Identity
private readonly Func<IAsyncDocumentSession> getSessionFunc;
private IAsyncDocumentSession _session;
/// <inheritdoc />
public UserStore(Func<IAsyncDocumentSession> getSession)
{
this.getSessionFunc = getSession;
}
/// <inheritdoc />
public UserStore(IAsyncDocumentSession session)
{
this._session = session;
@@ -46,6 +45,7 @@ namespace RavenDB.Identity
#region IDispoable implementation
/// <inheritdoc />
public void Dispose()
{
_disposed = true;
@@ -55,6 +55,7 @@ namespace RavenDB.Identity
#region IUserStore implementation
/// <inheritdoc />
public Task<string> GetUserIdAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -62,6 +63,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.Id);
}
/// <inheritdoc />
public Task<string> GetUserNameAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -69,6 +71,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.UserName);
}
/// <inheritdoc />
public Task SetUserNameAsync(TUser user, string userName, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -77,6 +80,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<string> GetNormalizedUserNameAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -85,6 +89,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.UserName);
}
/// <inheritdoc />
public Task SetNormalizedUserNameAsync(TUser user, string normalizedName, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -93,13 +98,19 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <summary>
/// Creates a user asynchronously.
/// </summary>
/// <param name="user"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<IdentityResult> 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;
}
/// <inheritdoc />
public Task<IdentityResult> UpdateAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -122,6 +134,7 @@ namespace RavenDB.Identity
return Task.FromResult(IdentityResult.Success);
}
/// <inheritdoc />
public async Task<IdentityResult> DeleteAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -138,6 +151,7 @@ namespace RavenDB.Identity
return IdentityResult.Success;
}
/// <inheritdoc />
public Task<TUser> FindByIdAsync(string userId, CancellationToken cancellationToken)
{
ThrowIfDisposedOrCancelled(cancellationToken);
@@ -145,6 +159,7 @@ namespace RavenDB.Identity
return DbSession.LoadAsync<TUser>(userId);
}
/// <inheritdoc />
public async Task<TUser> FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
{
ThrowIfDisposedOrCancelled(cancellationToken);
@@ -168,6 +183,7 @@ namespace RavenDB.Identity
#region IUserLoginStore implementation
/// <inheritdoc />
public async Task AddLoginAsync(TUser user, UserLoginInfo login, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -191,6 +207,7 @@ namespace RavenDB.Identity
}
}
/// <inheritdoc />
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);
}
/// <inheritdoc />
public Task<IList<UserLoginInfo>> GetLoginsAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -215,6 +233,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.Logins.ToIList());
}
/// <inheritdoc />
public async Task<TUser> 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
/// <inheritdoc />
public Task<IList<Claim>> GetClaimsAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -242,6 +262,7 @@ namespace RavenDB.Identity
return Task.FromResult(result);
}
/// <inheritdoc />
public Task AddClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -250,6 +271,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public async Task ReplaceClaimAsync(TUser user, Claim claim, Claim newClaim, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -262,6 +284,7 @@ namespace RavenDB.Identity
}
}
/// <inheritdoc />
public Task RemoveClaimsAsync(TUser user, IEnumerable<Claim> claims, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -270,7 +293,8 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
public Task<IList<TUser>> GetUsersForClaimAsync(Claim claim, CancellationToken cancellationToken)
/// <inheritdoc />
public async Task<IList<TUser>> 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<TUser>()
var list = await DbSession.Query<TUser>()
.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
}
}
/// <inheritdoc />
public Task<IList<string>> GetRolesAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -348,6 +374,7 @@ namespace RavenDB.Identity
return Task.FromResult<IList<string>>(new List<string>(user.Roles));
}
/// <inheritdoc />
public Task<bool> 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<IList<TUser>> GetUsersInRoleAsync(string roleName, CancellationToken cancellationToken)
/// <inheritdoc />
public async Task<IList<TUser>> 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<TUser>()
var users = await DbSession.Query<TUser>()
.Where(u => u.Roles.Contains(roleName, StringComparer.InvariantCultureIgnoreCase))
.Take(1024)
.ToListAsync();
return users;
}
#endregion
#region IUserPasswordStore implementation
/// <inheritdoc />
public Task SetPasswordHashAsync(TUser user, string passwordHash, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -384,6 +414,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<string> GetPasswordHashAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -391,6 +422,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.PasswordHash);
}
/// <inheritdoc />
public Task<bool> HasPasswordAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -402,6 +434,7 @@ namespace RavenDB.Identity
#region IUserSecurityStampStore implementation
/// <inheritdoc />
public Task SetSecurityStampAsync(TUser user, string stamp, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -410,6 +443,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<string> GetSecurityStampAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -421,6 +455,7 @@ namespace RavenDB.Identity
#region IUserEmailStore implementation
/// <inheritdoc />
public Task SetEmailAsync(TUser user, string email, CancellationToken cancellationToken)
{
ThrowIfDisposedOrCancelled(cancellationToken);
@@ -428,6 +463,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<string> GetEmailAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -435,6 +471,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.Email);
}
/// <inheritdoc />
public Task<bool> GetEmailConfirmedAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -442,6 +479,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.EmailConfirmed);
}
/// <inheritdoc />
public Task SetEmailConfirmedAsync(TUser user, bool confirmed, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -450,6 +488,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<TUser> FindByEmailAsync(string normalizedEmail, CancellationToken cancellationToken)
{
ThrowIfDisposedOrCancelled(cancellationToken);
@@ -458,6 +497,7 @@ namespace RavenDB.Identity
.FirstOrDefaultAsync(u => u.Email == normalizedEmail, cancellationToken);
}
/// <inheritdoc />
public Task<string> GetNormalizedEmailAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -466,6 +506,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.Email);
}
/// <inheritdoc />
public Task SetNormalizedEmailAsync(TUser user, string normalizedEmail, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -482,6 +523,7 @@ namespace RavenDB.Identity
#region IUserLockoutStore implementation
/// <inheritdoc />
public Task<DateTimeOffset?> GetLockoutEndDateAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -489,6 +531,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.LockoutEndDate);
}
/// <inheritdoc />
public Task SetLockoutEndDateAsync(TUser user, DateTimeOffset? lockoutEnd, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -497,6 +540,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<int> IncrementAccessFailedCountAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -505,6 +549,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.AccessFailedCount);
}
/// <inheritdoc />
public Task ResetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -513,6 +558,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<int> GetAccessFailedCountAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -520,12 +566,14 @@ namespace RavenDB.Identity
return Task.FromResult(user.AccessFailedCount);
}
/// <inheritdoc />
public Task<bool> GetLockoutEnabledAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
return Task.FromResult(user.LockoutEnabled);
}
/// <inheritdoc />
public Task SetLockoutEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -538,6 +586,7 @@ namespace RavenDB.Identity
#region IUserTwoFactorStore implementation
/// <inheritdoc />
public Task SetTwoFactorEnabledAsync(TUser user, bool enabled, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -546,6 +595,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<bool> GetTwoFactorEnabledAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -557,6 +607,7 @@ namespace RavenDB.Identity
#region IUserPhoneNumberStore implementation
/// <inheritdoc />
public Task SetPhoneNumberAsync(TUser user, string phoneNumber, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -565,6 +616,7 @@ namespace RavenDB.Identity
return Task.CompletedTask;
}
/// <inheritdoc />
public Task<string> GetPhoneNumberAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -572,6 +624,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.PhoneNumber);
}
/// <inheritdoc />
public Task<bool> GetPhoneNumberConfirmedAsync(TUser user, CancellationToken cancellationToken)
{
ThrowIfNullDisposedCancelled(user, cancellationToken);
@@ -579,6 +632,7 @@ namespace RavenDB.Identity
return Task.FromResult(user.IsPhoneNumberConfirmed);
}
/// <inheritdoc />
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<IdentityUser>((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<IdentityUser>((dbname, commands, user) => "IdentityUsers/" + user.Id);
}
return _session;
}
+1 -1
View File
@@ -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
{
+5 -9
View File
@@ -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
{
+6 -8
View File
@@ -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
{
+3 -5
View File
@@ -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
{
+1 -1
View File
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using RavenDB.Identity;
using Raven.Identity;
namespace Sample.Models
{
+13 -3
View File
@@ -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<AppUser>(); // Use Raven for users and roles.
// You can change the login path if need be.