Big cleanup and adding IdentityBuilder extensions the same way as the EF IdentityBuilder extensions do, allowing customer Identity setup.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>AspNetCore.Identity.MongoDbCore</id>
|
||||
<version>1.0.4</version>
|
||||
<version>1.0.5</version>
|
||||
<title>AspNetCore.Identity.MongoDbCore</title>
|
||||
<authors>Alexandre Spieser</authors>
|
||||
<owners>Alexandre Spieser</owners>
|
||||
@@ -10,7 +10,7 @@
|
||||
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.</description>
|
||||
<releaseNotes>Target both netstandard2.0 and netcoreapp2</releaseNotes>
|
||||
<releaseNotes>Added .AddMongoDbStores IdentityBuilder extensions.</releaseNotes>
|
||||
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||
<tags>aspnetcore mongo mongodb identity membership</tags>
|
||||
</metadata>
|
||||
|
||||
@@ -12,6 +12,11 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||
/// </summary>
|
||||
public static class ClaimHolderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="MongoClaim"/> object from a <see cref="Claim"/>
|
||||
/// </summary>
|
||||
/// <param name="claim">The <see cref="Claim"/>.</param>
|
||||
/// <returns>A <see cref="MongoClaim"/>.</returns>
|
||||
public static MongoClaim ToMongoClaim(this Claim claim)
|
||||
{
|
||||
return new MongoClaim
|
||||
@@ -22,9 +27,14 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||
};
|
||||
}
|
||||
|
||||
public static Claim ToClaim(this MongoClaim claim)
|
||||
/// <summary>
|
||||
/// Creates a <see cref="Claim"/> object from a <see cref="MongoClaim"/>
|
||||
/// </summary>
|
||||
/// <param name="mongoClaim">A <see cref="MongoClaim"/>.</param>
|
||||
/// <returns> A <see cref="Claim"/>.</returns>
|
||||
public static Claim ToClaim(this MongoClaim mongoClaim)
|
||||
{
|
||||
return new Claim(claim.Type, claim.Value, null, claim.Issuer);
|
||||
return new Claim(mongoClaim.Type, mongoClaim.Value, null, mongoClaim.Issuer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,6 +95,12 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||
return claimHolder.Claims.Any(e => e.Value == claim.Value && e.Type == claim.Type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a <see cref="Claim"/> from the <see cref="IClaimHolder"/>.
|
||||
/// </summary>
|
||||
/// <param name="claimHolder">The holder of the claim.</param>
|
||||
/// <param name="claim">The <see cref="Claim"/> to remove.</param>
|
||||
/// <returns>True is the claim was successfully removed.</returns>
|
||||
public static bool RemoveClaim(this IClaimHolder claimHolder, Claim claim)
|
||||
{
|
||||
if (claim == null)
|
||||
@@ -102,6 +118,12 @@ namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes an IEnumerable of <see cref="Claim"/>s from the <see cref="IClaimHolder"/>.
|
||||
/// </summary>
|
||||
/// <param name="claimHolder">The holder of the claims.</param>
|
||||
/// <param name="claims">The <see cref="Claim"/>s to remove.</param>
|
||||
/// <returns>True is the claims were successfully removed.</returns>
|
||||
public static bool RemoveClaims(this IClaimHolder claimHolder, IEnumerable<Claim> claims)
|
||||
{
|
||||
var someClaimsRemoved = false;
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using MongoDbGenericRepository;
|
||||
using AspNetCore.Identity.MongoDbCore;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
using AspNetCore.Identity.MongoDbCore.Infrastructure;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extension methods to <see cref="IdentityBuilder"/> for adding MongoDb stores.
|
||||
/// </summary>
|
||||
public static class MongoDbIdentityBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds an MongoDb implementation of identity information stores.
|
||||
/// </summary>
|
||||
/// <typeparam name="TContext">The MongoDb database context to use.</typeparam>
|
||||
/// <param name="builder">The <see cref="IdentityBuilder"/> instance this method extends.</param>
|
||||
/// <param name="mongoDbContext">A mongoDbContext</param>
|
||||
/// <returns>The <see cref="IdentityBuilder"/> instance this method extends.</returns>
|
||||
public static IdentityBuilder AddMongoDbStores<TContext>(this IdentityBuilder builder, IMongoDbContext mongoDbContext)
|
||||
where TContext : IMongoDbContext
|
||||
{
|
||||
if(mongoDbContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mongoDbContext));
|
||||
}
|
||||
|
||||
builder.Services.TryAddSingleton<IMongoDbContext>(mongoDbContext);
|
||||
builder.Services.TryAddSingleton<IMongoRepository>(new MongoRepository(mongoDbContext));
|
||||
|
||||
AddStores(builder.Services, builder.UserType, builder.RoleType, typeof(TContext));
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an MongoDb implementation of identity information stores.
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser">The type representing a user.</typeparam>
|
||||
/// <typeparam name="TRole">The type representing a role.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key of the identity document.</typeparam>
|
||||
/// <param name="builder">The <see cref="IdentityBuilder"/> instance this method extends.</param>
|
||||
/// <param name="connectionString"></param>
|
||||
/// <param name="databaseName"></param>
|
||||
public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this IdentityBuilder builder, string connectionString, string databaseName)
|
||||
where TUser : MongoIdentityUser<TKey>, new()
|
||||
where TRole : MongoIdentityRole<TKey>, new()
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
if (string.IsNullOrEmpty(connectionString))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(connectionString));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(databaseName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(databaseName));
|
||||
}
|
||||
builder.Services.TryAddSingleton<MongoDbSettings>(new MongoDbSettings
|
||||
{
|
||||
ConnectionString = connectionString,
|
||||
DatabaseName = databaseName
|
||||
});
|
||||
builder.AddMongoDbStores<TUser, TRole, TKey>(new MongoDbContext(connectionString, databaseName));
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds an MongoDb implementation of identity information stores.
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser">The type representing a user.</typeparam>
|
||||
/// <typeparam name="TRole">The type representing a role.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key of the identity document.</typeparam>
|
||||
/// <param name="builder">The <see cref="IdentityBuilder"/> instance this method extends.</param>
|
||||
/// <param name="mongoDbContext"></param>
|
||||
public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this IdentityBuilder builder, IMongoDbContext mongoDbContext)
|
||||
where TUser : MongoIdentityUser<TKey>, new()
|
||||
where TRole : MongoIdentityRole<TKey>, new()
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
if (mongoDbContext == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mongoDbContext));
|
||||
}
|
||||
|
||||
builder.Services.TryAddSingleton<IMongoDbContext>(mongoDbContext);
|
||||
builder.Services.TryAddSingleton<IMongoRepository>(new MongoRepository(mongoDbContext));
|
||||
builder.Services.TryAddScoped<IUserStore<TUser>>(provider =>
|
||||
{
|
||||
return new MongoUserStore<TUser, TRole, IMongoDbContext, TKey>(provider.GetService<IMongoDbContext>());
|
||||
});
|
||||
|
||||
builder.Services.TryAddScoped<IRoleStore<TRole>>(provider =>
|
||||
{
|
||||
return new MongoRoleStore<TRole, IMongoDbContext, TKey>(provider.GetService<IMongoDbContext>());
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static void AddStores(IServiceCollection services, Type userType, Type roleType, Type contextType)
|
||||
{
|
||||
var identityUserType = FindGenericBaseType(userType, typeof(MongoIdentityUser<>));
|
||||
if (identityUserType == null)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.NotIdentityUser);
|
||||
}
|
||||
|
||||
var keyType = identityUserType.GenericTypeArguments[0];
|
||||
|
||||
if (roleType != null)
|
||||
{
|
||||
var identityRoleType = FindGenericBaseType(roleType, typeof(MongoIdentityRole<>));
|
||||
if (identityRoleType == null)
|
||||
{
|
||||
throw new InvalidOperationException(Resources.NotIdentityRole);
|
||||
}
|
||||
|
||||
Type userStoreType = null;
|
||||
Type roleStoreType = null;
|
||||
|
||||
// If its a custom DbContext, we can only add the default POCOs
|
||||
userStoreType = typeof(MongoUserStore<,,,>).MakeGenericType(userType, roleType, contextType, keyType);
|
||||
roleStoreType = typeof(MongoRoleStore<,,>).MakeGenericType(roleType, contextType, keyType);
|
||||
|
||||
services.TryAddSingleton(typeof(IUserStore<>).MakeGenericType(userType), userStoreType);
|
||||
services.TryAddSingleton(typeof(IRoleStore<>).MakeGenericType(roleType), roleStoreType);
|
||||
}
|
||||
else
|
||||
{ // No Roles
|
||||
Type userStoreType = null;
|
||||
// If its a custom DbContext, we can only add the default POCOs
|
||||
userStoreType = typeof(MongoUserStore<,,,>).MakeGenericType(userType, roleType, contextType, keyType);
|
||||
services.TryAddSingleton(typeof(IUserStore<>).MakeGenericType(userType), userStoreType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static TypeInfo FindGenericBaseType(Type currentType, Type genericBaseType)
|
||||
{
|
||||
var type = currentType;
|
||||
while (type != null)
|
||||
{
|
||||
var typeInfo = type.GetTypeInfo();
|
||||
var genericType = type.IsGenericType ? type.GetGenericTypeDefinition() : null;
|
||||
if (genericType != null && genericType == genericBaseType)
|
||||
{
|
||||
return typeInfo;
|
||||
}
|
||||
type = type.BaseType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,88 +7,118 @@ using System;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||
{
|
||||
public class MongoDbSettings
|
||||
{
|
||||
public string ConnectionString { get; set; }
|
||||
public string DatabaseName { get; set; }
|
||||
}
|
||||
|
||||
public class MongoDbIdentityConfiguration
|
||||
{
|
||||
public MongoDbSettings MongoDbSettings { get; set; }
|
||||
public Action<IdentityOptions> IdentityOptionsAction { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Contains extension methods to <see cref="IServiceCollection"/> for adding mongoDb Identity.
|
||||
/// </summary>
|
||||
public static class ServiceCollectionExtension
|
||||
{
|
||||
public static void ConfigureMongoDbIdentity<TUser, TKey>(
|
||||
this IServiceCollection services,
|
||||
MongoDbIdentityConfiguration mongoDbIdentityConfiguration,
|
||||
IMongoRepository mongoRepository = null)
|
||||
/// <summary>
|
||||
/// Configures the MongoDb Identity store adapters for the types of TUser only from <see cref="MongoIdentityUser{TKey}"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser">The type representing a user.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key of the identity document.</typeparam>
|
||||
/// <param name="services">The collection of service descriptors.</param>
|
||||
/// <param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||
public static void ConfigureMongoDbIdentityUserOnly<TUser, TKey>(
|
||||
this IServiceCollection services,
|
||||
MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
|
||||
where TUser : MongoIdentityUser<TKey>, new()
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
services.AddSingleton<MongoDbSettings>(mongoDbIdentityConfiguration.MongoDbSettings);
|
||||
services.AddSingleton<IMongoRepository>(provider =>
|
||||
{
|
||||
var options = provider.GetService<MongoDbSettings>();
|
||||
return mongoRepository ?? new MongoRepository(options.ConnectionString, options.DatabaseName);
|
||||
});
|
||||
|
||||
ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings);
|
||||
CommonMongoDbSetup<TUser, MongoIdentityRole<TKey>, TKey>(services, mongoDbIdentityConfiguration);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Configures the MongoDb Identity store adapters for the types of TUser only inheriting from <see cref="MongoIdentityUser"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser">The type representing a user.</typeparam>
|
||||
/// <param name="services">The collection of service descriptors.</param>
|
||||
/// <param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||
public static void ConfigureMongoDbIdentity<TUser>(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
|
||||
where TUser : MongoIdentityUser, new()
|
||||
{
|
||||
services.AddSingleton<MongoDbSettings>(mongoDbIdentityConfiguration.MongoDbSettings);
|
||||
services.AddSingleton<IMongoRepository>(provider =>
|
||||
{
|
||||
var options = provider.GetService<MongoDbSettings>();
|
||||
return new MongoRepository(options.ConnectionString, options.DatabaseName);
|
||||
});
|
||||
|
||||
ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings);
|
||||
CommonMongoDbSetup<TUser, MongoIdentityRole, Guid>(services, mongoDbIdentityConfiguration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the MongoDbSettings
|
||||
/// </summary>
|
||||
/// <param name="mongoDbSettings"></param>
|
||||
private static void ValidateMongoDbSettings(MongoDbSettings mongoDbSettings)
|
||||
{
|
||||
if (mongoDbSettings == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mongoDbSettings));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(mongoDbSettings.ConnectionString))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mongoDbSettings.ConnectionString));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(mongoDbSettings.DatabaseName))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(mongoDbSettings.DatabaseName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the MongoDb Identity store adapters for the types of TUser and TRole.
|
||||
/// </summary>
|
||||
/// <typeparam name="TUser">The type representing a user.</typeparam>
|
||||
/// <typeparam name="TRole">The type representing a role.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key of the identity document.</typeparam>
|
||||
/// <param name="services">The collection of service descriptors.</param>
|
||||
/// <param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||
/// <param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
||||
public static void ConfigureMongoDbIdentity<TUser, TRole, TKey>(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration,
|
||||
IMongoDbContext mongoDbContext = null)
|
||||
where TUser : MongoIdentityUser<TKey>, new()
|
||||
where TRole : MongoIdentityRole<TKey>, new()
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
services.AddSingleton<MongoDbSettings>(mongoDbIdentityConfiguration.MongoDbSettings);
|
||||
services.AddSingleton<IMongoRepository>(provider =>
|
||||
{
|
||||
var options = provider.GetService<MongoDbSettings>();
|
||||
return mongoDbContext == null ? new MongoRepository(options.ConnectionString, options.DatabaseName) : new MongoRepository(mongoDbContext);
|
||||
});
|
||||
ValidateMongoDbSettings(mongoDbIdentityConfiguration.MongoDbSettings);
|
||||
|
||||
CommonMongoDbSetup<TUser, TRole, TKey>(services, mongoDbIdentityConfiguration);
|
||||
if(mongoDbContext == null)
|
||||
{
|
||||
services.AddIdentity<TUser, TRole>()
|
||||
.AddMongoDbStores<TUser, TRole, TKey>(
|
||||
mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
|
||||
mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName)
|
||||
.AddDefaultTokenProviders();
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddIdentity<TUser, TRole>()
|
||||
.AddMongoDbStores<IMongoDbContext>(mongoDbContext)
|
||||
.AddDefaultTokenProviders();
|
||||
}
|
||||
|
||||
if (mongoDbIdentityConfiguration.IdentityOptionsAction != null)
|
||||
{
|
||||
services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void CommonMongoDbSetup<TUser, TRole, TKey>(this IServiceCollection services, MongoDbIdentityConfiguration mongoDbIdentityConfiguration)
|
||||
where TUser : MongoIdentityUser<TKey>, new()
|
||||
where TRole : MongoIdentityRole<TKey>, new()
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
services.AddScoped<IUserStore<TUser>>(provider =>
|
||||
{
|
||||
var userStore = new MongoUserStore<TUser, TRole, IMongoDbContext, TKey>(provider.GetService<IMongoRepository>().Context);
|
||||
return userStore;
|
||||
});
|
||||
|
||||
services.AddScoped<IRoleStore<TRole>>(provider =>
|
||||
{
|
||||
return new MongoRoleStore<TRole, IMongoDbContext, TKey>(provider.GetService<IMongoRepository>().Context);
|
||||
});
|
||||
|
||||
services.AddIdentity<TUser, TRole>()
|
||||
.AddMongoDbStores<TUser, TRole, TKey>(
|
||||
mongoDbIdentityConfiguration.MongoDbSettings.ConnectionString,
|
||||
mongoDbIdentityConfiguration.MongoDbSettings.DatabaseName)
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
services.Configure<IdentityOptions>(mongoDbIdentityConfiguration.IdentityOptionsAction);
|
||||
if (mongoDbIdentityConfiguration.IdentityOptionsAction != null)
|
||||
{
|
||||
services.Configure(mongoDbIdentityConfiguration.IdentityOptionsAction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,14 @@
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore
|
||||
{
|
||||
/// <summary>
|
||||
/// A class holding global variables.
|
||||
/// </summary>
|
||||
public static class GlobalVariables
|
||||
{
|
||||
/// <summary>
|
||||
/// A random number generator.
|
||||
/// </summary>
|
||||
public static Random Random = new Random();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using System;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// A class used to perform a full configuration of the AspNetCore.Identity.MongoDbCore package.
|
||||
/// </summary>
|
||||
public class MongoDbIdentityConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// The settings for the MongoDb server.
|
||||
/// </summary>
|
||||
public MongoDbSettings MongoDbSettings { get; set; }
|
||||
/// <summary>
|
||||
/// An action against an <see cref="IdentityOptions"/> to change the default identity settings.
|
||||
/// </summary>
|
||||
public Action<IdentityOptions> IdentityOptionsAction { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace AspNetCore.Identity.MongoDbCore.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// A class representing the settings for the MongoDb server.
|
||||
/// </summary>
|
||||
public class MongoDbSettings
|
||||
{
|
||||
/// <summary>
|
||||
/// The connection string for the MongoDb server.
|
||||
/// </summary>
|
||||
public string ConnectionString { get; set; }
|
||||
/// <summary>
|
||||
/// The name of the MongoDb database where the identity data will be stored.
|
||||
/// </summary>
|
||||
public string DatabaseName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -2,34 +2,74 @@
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Infrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// The repository used in the MongoDb identity stores.
|
||||
/// </summary>
|
||||
public interface IMongoRepository : IBaseMongoRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Drops a collections.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type of the document used to define the collection name.</typeparam>
|
||||
void DropCollection<TDocument>();
|
||||
|
||||
/// <summary>
|
||||
/// Drops a partitioned collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type of the document used to define the collection name.</typeparam>
|
||||
/// <param name="partitionKey">The partition key of the collection.</param>
|
||||
void DropCollection<TDocument>(string partitionKey);
|
||||
|
||||
/// <summary>
|
||||
/// The MongoDb context.
|
||||
/// </summary>
|
||||
IMongoDbContext Context { get; }
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The repository used in the MongoDb identity stores.
|
||||
/// </summary>
|
||||
public class MongoRepository : BaseMongoRepository, IMongoRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// The constructor for <see cref="MongoRepository"/> requiring a connection string and a database name.
|
||||
/// </summary>
|
||||
/// <param name="connectionString">The connection string.</param>
|
||||
/// <param name="databaseName">The database name.</param>
|
||||
public MongoRepository(string connectionString, string databaseName) : base(connectionString, databaseName)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for <see cref="MongoRepository"/> requiring a <see cref="IMongoDbContext"/>.
|
||||
/// </summary>
|
||||
/// <param name="mongoDbContext">A <see cref="IMongoDbContext"/>.</param>
|
||||
public MongoRepository(IMongoDbContext mongoDbContext) : base(mongoDbContext)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops a collections.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type of the document used to define the collection name.</typeparam>
|
||||
public void DropCollection<TDocument>()
|
||||
{
|
||||
MongoDbContext.DropCollection<TDocument>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops a partitioned collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocument">The type of the document used to define the collection name.</typeparam>
|
||||
/// <param name="partitionKey">The partition key of the collection.</param>
|
||||
public void DropCollection<TDocument>(string partitionKey)
|
||||
{
|
||||
MongoDbContext.DropCollection<TDocument>(partitionKey);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The MongoDb context.
|
||||
/// </summary>
|
||||
public IMongoDbContext Context => MongoDbContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ namespace AspNetCore.Identity.MongoDbCore.Interfaces
|
||||
/// </summary>
|
||||
public interface IClaimHolder
|
||||
{
|
||||
/// <summary>
|
||||
/// The claims the <see cref="IClaimHolder"/> has.
|
||||
/// </summary>
|
||||
List<MongoClaim> Claims { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A class representing the claims a <see cref="MongoIdentityUser{TKey}"/> can have.
|
||||
/// </summary>
|
||||
public class MongoClaim
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of the claim.
|
||||
/// </summary>
|
||||
public string Type { get; set; }
|
||||
/// <summary>
|
||||
/// The value of the claim.
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
/// <summary>
|
||||
/// The issuer of the claim.
|
||||
/// </summary>
|
||||
public string Issuer { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -3,32 +3,55 @@ using Microsoft.AspNetCore.Identity;
|
||||
using MongoDbGenericRepository.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="MongoIdentityRole{TKey}"/> where TKey is a <see cref="string"/>
|
||||
/// </summary>
|
||||
public class MongoDbIdentityRole : MongoIdentityRole<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityRole"/>
|
||||
/// </summary>
|
||||
public MongoDbIdentityRole() : base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityRole"/>, taking a role name.
|
||||
/// </summary>
|
||||
/// <param name="roleName">The name of the role.</param>
|
||||
public MongoDbIdentityRole(string roleName) : base(roleName)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="MongoIdentityRole{TKey}"/> where TKey is a <see cref="Guid"/>
|
||||
/// </summary>
|
||||
public class MongoIdentityRole : MongoIdentityRole<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole"/>
|
||||
/// </summary>
|
||||
public MongoIdentityRole() : base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole"/>, taking a role name.
|
||||
/// </summary>
|
||||
/// <param name="roleName">The name of the role.</param>
|
||||
public MongoIdentityRole(string roleName) : base(roleName)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A document representing an <see cref="IdentityRole{TKey}"/> document.
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey">The type of the primary key.</typeparam>
|
||||
public class MongoIdentityRole<TKey> : IdentityRole<TKey>, IDocument<TKey>, IClaimHolder
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
@@ -53,17 +76,29 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>
|
||||
/// </summary>
|
||||
public MongoIdentityRole()
|
||||
{
|
||||
InitializeFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name.
|
||||
/// </summary>
|
||||
/// <param name="roleName">The name of the role.</param>
|
||||
public MongoIdentityRole(string roleName)
|
||||
{
|
||||
Name = roleName;
|
||||
InitializeFields();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name and a primary key value.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the role.</param>
|
||||
/// <param name="key">The value of the primary key</param>
|
||||
public MongoIdentityRole(string name, TKey key)
|
||||
{
|
||||
InitializeFields();
|
||||
|
||||
@@ -8,58 +8,62 @@ using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
{
|
||||
public class Token
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the LoginProvider this token is from.
|
||||
/// </summary>
|
||||
public string LoginProvider { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the token.
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the token value.
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
public class MongoClaim {
|
||||
public string Type { get; set; }
|
||||
public string Value { get; set; }
|
||||
public string Issuer { get; set; }
|
||||
}
|
||||
|
||||
public class UserRole
|
||||
{
|
||||
public object UserId { get; set; }
|
||||
public object RoleId { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="MongoIdentityUser{TKey}"/> where TKey is a <see cref="string"/>
|
||||
/// </summary>
|
||||
public class MongoDbIdentityUser : MongoIdentityUser<string>
|
||||
{
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityUser"/>
|
||||
/// </summary>
|
||||
public MongoDbIdentityUser() : base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityUser"/>, taking a username.
|
||||
/// </summary>
|
||||
/// <param name="userName">The name of the user.</param>
|
||||
public MongoDbIdentityUser(string userName) : base(userName)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityUser"/>, taking a username and an email address.
|
||||
/// </summary>
|
||||
/// <param name="userName">The name of the user.</param>
|
||||
/// <param name="email">The email address of the user.</param>
|
||||
public MongoDbIdentityUser(string userName, string email) : base(userName, email)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A <see cref="MongoIdentityUser{TKey}"/> where TKey is a <see cref="Guid"/>
|
||||
/// </summary>
|
||||
public class MongoIdentityUser : MongoIdentityUser<Guid>
|
||||
{
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoIdentityUser"/>
|
||||
/// </summary>
|
||||
public MongoIdentityUser() : base()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityUser"/>, taking a username.
|
||||
/// </summary>
|
||||
/// <param name="userName">The name of the user.</param>
|
||||
public MongoIdentityUser(string userName) : base(userName)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The constructor for a <see cref="MongoDbIdentityUser"/>, taking a username and an email address.
|
||||
/// </summary>
|
||||
/// <param name="userName">The name of the user.</param>
|
||||
/// <param name="email">The email address of the user.</param>
|
||||
public MongoIdentityUser(string userName, string email) : base(userName, email)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// A class representing the tokens a <see cref="MongoIdentityUser{TKey}"/> can have.
|
||||
/// </summary>
|
||||
public class Token
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the LoginProvider this token is from.
|
||||
/// </summary>
|
||||
public string LoginProvider { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the token.
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the token value.
|
||||
/// </summary>
|
||||
public string Value { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the password hashing options
|
||||
/// </summary>
|
||||
public sealed class PasswordHasherOptionsAccessor : IOptions<PasswordHasherOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations
|
||||
/// (roughly 200ms of work)
|
||||
/// </summary>
|
||||
public PasswordHasherOptions Value { get; } = new PasswordHasherOptions
|
||||
{
|
||||
CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3,
|
||||
IterationCount = 200000
|
||||
};
|
||||
}
|
||||
|
||||
public static class MongoIdentityServiceCollectionExtensions
|
||||
{
|
||||
public static IdentityBuilder AddIdentity<TUser>(this IServiceCollection services)
|
||||
where TUser : class => services.AddIdentity<TUser>(null);
|
||||
|
||||
public static IdentityBuilder AddIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> setupAction)
|
||||
where TUser : class
|
||||
{
|
||||
// Hosting doesn't add IHttpContextAccessor by default
|
||||
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||
|
||||
// Identity services
|
||||
services.TryAddScoped<IUserValidator<TUser>, UserValidator<TUser>>();
|
||||
services.TryAddScoped<IPasswordValidator<TUser>, PasswordValidator<TUser>>();
|
||||
|
||||
services.TryAddScoped<IPasswordHasher<TUser>, PasswordHasher<TUser>>();
|
||||
services.TryAddScoped<ILookupNormalizer, UpperInvariantLookupNormalizer>();
|
||||
|
||||
// No interface for the error describer so we can add errors without rev'ing the interface
|
||||
services.TryAddScoped<IdentityErrorDescriber>();
|
||||
services.TryAddScoped<ISecurityStampValidator, SecurityStampValidator<TUser>>();
|
||||
services.TryAddScoped<IUserClaimsPrincipalFactory<TUser>, UserClaimsPrincipalFactory<TUser>>();
|
||||
services.TryAddScoped<UserManager<TUser>, AspNetUserManager<TUser>>();
|
||||
services.TryAddScoped<SignInManager<TUser>, SignInManager<TUser>>();
|
||||
|
||||
if (setupAction != null)
|
||||
{
|
||||
services.Configure(setupAction);
|
||||
}
|
||||
|
||||
return new IdentityBuilder(typeof(TUser), services);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,9 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
where TUser : MongoIdentityUser<string>, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a new instance of <see cref="UserOnlyStore{TUser}"/>.
|
||||
/// Constructs a new instance of <see cref="MongoUserOnlyStore{TUser}"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="DbContext"/>.</param>
|
||||
/// <param name="context">The <see cref="IMongoDbContext"/>.</param>
|
||||
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
|
||||
public MongoUserOnlyStore(IMongoDbContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
|
||||
}
|
||||
@@ -41,9 +41,9 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
where TContext : IMongoDbContext
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a new instance of <see cref="UserStore{TUser, TRole, TContext}"/>.
|
||||
/// Constructs a new instance of <see cref="MongoUserOnlyStore{TUser, TContext}"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="DbContext"/>.</param>
|
||||
/// <param name="context">The <see cref="IMongoDbContext"/>.</param>
|
||||
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
|
||||
public MongoUserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
|
||||
}
|
||||
@@ -60,9 +60,9 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
where TKey : IEquatable<TKey>
|
||||
{
|
||||
/// <summary>
|
||||
/// Constructs a new instance of <see cref="UserStore{TUser, TRole, TContext, TKey}"/>.
|
||||
/// Constructs a new instance of <see cref="MongoUserOnlyStore{TUser, TContext, TKey}"/>.
|
||||
/// </summary>
|
||||
/// <param name="context">The <see cref="DbContext"/>.</param>
|
||||
/// <param name="context">The <see cref="IMongoDbContext"/>.</param>
|
||||
/// <param name="describer">The <see cref="IdentityErrorDescriber"/>.</param>
|
||||
public MongoUserOnlyStore(TContext context, IdentityErrorDescriber describer = null) : base(context, describer) { }
|
||||
}
|
||||
@@ -74,10 +74,8 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
/// <typeparam name="TContext">The type of the data context class used to access the store.</typeparam>
|
||||
/// <typeparam name="TKey">The type of the primary key for a role.</typeparam>
|
||||
/// <typeparam name="TUserClaim">The type representing a claim.</typeparam>
|
||||
/// <typeparam name="TUserRole">The type representing a user role.</typeparam>
|
||||
/// <typeparam name="TUserLogin">The type representing a user external login.</typeparam>
|
||||
/// <typeparam name="TUserToken">The type representing a user token.</typeparam>
|
||||
/// <typeparam name="TRoleClaim">The type representing a role claim.</typeparam>
|
||||
public class MongoUserOnlyStore<TUser, TContext, TKey, TUserClaim, TUserLogin, TUserToken> :
|
||||
UserStoreBase<TUser, TKey, TUserClaim, TUserLogin, TUserToken>,
|
||||
IUserAuthenticationTokenStore<TUser>
|
||||
@@ -543,10 +541,6 @@ namespace AspNetCore.Identity.MongoDbCore
|
||||
|
||||
#region Token Management
|
||||
|
||||
public class TokenProjection
|
||||
{
|
||||
public List<Token> Tokens { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Find a user token if it exists.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the password hashing options
|
||||
/// </summary>
|
||||
public sealed class PasswordHasherOptionsAccessor : IOptions<PasswordHasherOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations
|
||||
/// (roughly 200ms of work)
|
||||
/// </summary>
|
||||
public PasswordHasherOptions Value { get; } = new PasswordHasherOptions
|
||||
{
|
||||
CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3,
|
||||
IterationCount = 200000
|
||||
};
|
||||
}
|
||||
}
|
||||
Generated
+2
-2
@@ -61,7 +61,7 @@ namespace AspNetCore.Identity.MongoDbCore {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>..
|
||||
/// Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>..
|
||||
/// </summary>
|
||||
internal static string NotIdentityRole {
|
||||
get {
|
||||
@@ -70,7 +70,7 @@ namespace AspNetCore.Identity.MongoDbCore {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>..
|
||||
/// Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>..
|
||||
/// </summary>
|
||||
internal static string NotIdentityUser {
|
||||
get {
|
||||
|
||||
+4
-4
@@ -118,12 +118,12 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NotIdentityRole" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from IdentityRole</comment>
|
||||
<value>AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from MongoIdentityRole</comment>
|
||||
</data>
|
||||
<data name="NotIdentityUser" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from IdentityUser</comment>
|
||||
<value>AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from MongoIdentityUser</comment>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
<value>Role {0} does not exist.</value>
|
||||
|
||||
Binary file not shown.
@@ -34,6 +34,53 @@
|
||||
<param name="claim">The claim you want to replace.</param>
|
||||
<returns>Returns true if the claim is present, false otherwise.</returns>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.ServiceCollectionExtension.ValidateMongoDbSettings(AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings)">
|
||||
<summary>
|
||||
Validates the MongoDbSettings
|
||||
</summary>
|
||||
<param name="mongoDbSettings"></param>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.ServiceCollectionExtension.ConfigureMongoDbIdentity``3(Microsoft.Extensions.DependencyInjection.IServiceCollection,AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration,MongoDbGenericRepository.IMongoDbContext)">
|
||||
<summary>
|
||||
Configures the MongoDb Identity store adapters for
|
||||
</summary>
|
||||
<typeparam name="TUser"></typeparam>
|
||||
<typeparam name="TRole"></typeparam>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="services"></param>
|
||||
<param name="mongoDbIdentityConfiguration"></param>
|
||||
<param name="mongoDbContext"></param>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration">
|
||||
<summary>
|
||||
A class used to perform a full configuration of the AspNetCore.Identity.MongoDbCore package.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration.MongoDbSettings">
|
||||
<summary>
|
||||
The settings for the MongoDb server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration.IdentityOptionsAction">
|
||||
<summary>
|
||||
An action against an <see cref="T:Microsoft.AspNetCore.Identity.IdentityOptions"/> to change the default identity settings.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings">
|
||||
<summary>
|
||||
A class representing the settings for the MongoDb server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings.ConnectionString">
|
||||
<summary>
|
||||
The connection string for the MongoDb server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings.DatabaseName">
|
||||
<summary>
|
||||
The name of the MongoDb database where the identity data will be stored.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Interfaces.IClaimHolder">
|
||||
<summary>
|
||||
The interface for an object that holds claims.
|
||||
@@ -69,17 +116,6 @@
|
||||
<param name="newClaim">The new claim you want to set.</param>
|
||||
<returns>Returns true if the claim was replaced.</returns>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor">
|
||||
<summary>
|
||||
Represents the password hashing options
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor.Value">
|
||||
<summary>
|
||||
Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations
|
||||
(roughly 200ms of work)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.MongoRoleStore`1">
|
||||
<summary>
|
||||
Creates a new instance of a persistence store for roles.
|
||||
@@ -1335,6 +1371,17 @@
|
||||
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
<returns>True if the recovery code was found for the user.</returns>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor">
|
||||
<summary>
|
||||
Represents the password hashing options
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor.Value">
|
||||
<summary>
|
||||
Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations
|
||||
(roughly 200ms of work)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Resources">
|
||||
<summary>
|
||||
Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
|
||||
@@ -1353,12 +1400,12 @@
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Resources.NotIdentityRole">
|
||||
<summary>
|
||||
Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>..
|
||||
Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>..
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Resources.NotIdentityUser">
|
||||
<summary>
|
||||
Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>..
|
||||
Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>..
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Resources.RoleNotFound">
|
||||
@@ -1371,5 +1418,40 @@
|
||||
Recherche une chaîne localisée semblable à Value cannot be null or empty..
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions">
|
||||
<summary>
|
||||
Contains extension methods to <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> for adding MongoDb stores.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores``1(Microsoft.AspNetCore.Identity.IdentityBuilder,MongoDbGenericRepository.IMongoDbContext)">
|
||||
<summary>
|
||||
Adds an MongoDb implementation of identity information stores.
|
||||
</summary>
|
||||
<typeparam name="TContext">The MongoDb database context to use.</typeparam>
|
||||
<param name="builder">The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</param>
|
||||
<param name="mongoDbContext">A mongoDbContext</param>
|
||||
<returns>The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores``3(Microsoft.AspNetCore.Identity.IdentityBuilder,System.String,System.String)">
|
||||
<summary>
|
||||
Adds an MongoDb implementation of identity information stores.
|
||||
</summary>
|
||||
<typeparam name="TUser"></typeparam>
|
||||
<typeparam name="TRole"></typeparam>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="builder">The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</param>
|
||||
<param name="connectionString"></param>
|
||||
<param name="databaseName"></param>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores``3(Microsoft.AspNetCore.Identity.IdentityBuilder,MongoDbGenericRepository.IMongoDbContext)">
|
||||
<summary>
|
||||
Adds an MongoDb implementation of identity information stores.
|
||||
</summary>
|
||||
<typeparam name="TUser"></typeparam>
|
||||
<typeparam name="TRole"></typeparam>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="builder">The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</param>
|
||||
<param name="mongoDbContext"></param>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -118,12 +118,12 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NotIdentityRole" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from IdentityRole</comment>
|
||||
<value>AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from MongoIdentityRole</comment>
|
||||
</data>
|
||||
<data name="NotIdentityUser" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from IdentityUser</comment>
|
||||
<value>AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from MongoIdentityUser</comment>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
<value>Role {0} does not exist.</value>
|
||||
|
||||
Binary file not shown.
@@ -34,6 +34,53 @@
|
||||
<param name="claim">The claim you want to replace.</param>
|
||||
<returns>Returns true if the claim is present, false otherwise.</returns>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.ServiceCollectionExtension.ValidateMongoDbSettings(AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings)">
|
||||
<summary>
|
||||
Validates the MongoDbSettings
|
||||
</summary>
|
||||
<param name="mongoDbSettings"></param>
|
||||
</member>
|
||||
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.ServiceCollectionExtension.ConfigureMongoDbIdentity``3(Microsoft.Extensions.DependencyInjection.IServiceCollection,AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration,MongoDbGenericRepository.IMongoDbContext)">
|
||||
<summary>
|
||||
Configures the MongoDb Identity store adapters for
|
||||
</summary>
|
||||
<typeparam name="TUser"></typeparam>
|
||||
<typeparam name="TRole"></typeparam>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="services"></param>
|
||||
<param name="mongoDbIdentityConfiguration"></param>
|
||||
<param name="mongoDbContext"></param>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration">
|
||||
<summary>
|
||||
A class used to perform a full configuration of the AspNetCore.Identity.MongoDbCore package.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration.MongoDbSettings">
|
||||
<summary>
|
||||
The settings for the MongoDb server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbIdentityConfiguration.IdentityOptionsAction">
|
||||
<summary>
|
||||
An action against an <see cref="T:Microsoft.AspNetCore.Identity.IdentityOptions"/> to change the default identity settings.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings">
|
||||
<summary>
|
||||
A class representing the settings for the MongoDb server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings.ConnectionString">
|
||||
<summary>
|
||||
The connection string for the MongoDb server.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Infrastructure.MongoDbSettings.DatabaseName">
|
||||
<summary>
|
||||
The name of the MongoDb database where the identity data will be stored.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Interfaces.IClaimHolder">
|
||||
<summary>
|
||||
The interface for an object that holds claims.
|
||||
@@ -69,17 +116,6 @@
|
||||
<param name="newClaim">The new claim you want to set.</param>
|
||||
<returns>Returns true if the claim was replaced.</returns>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor">
|
||||
<summary>
|
||||
Represents the password hashing options
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor.Value">
|
||||
<summary>
|
||||
Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations
|
||||
(roughly 200ms of work)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.MongoRoleStore`1">
|
||||
<summary>
|
||||
Creates a new instance of a persistence store for roles.
|
||||
@@ -1335,6 +1371,17 @@
|
||||
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||
<returns>True if the recovery code was found for the user.</returns>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor">
|
||||
<summary>
|
||||
Represents the password hashing options
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.PasswordHasherOptionsAccessor.Value">
|
||||
<summary>
|
||||
Gets options which use the IdentityV3 compat mode, and set the iteration count to 200000 PBKDF2-SHA256 iterations
|
||||
(roughly 200ms of work)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:AspNetCore.Identity.MongoDbCore.Resources">
|
||||
<summary>
|
||||
Une classe de ressource fortement typée destinée, entre autres, à la consultation des chaînes localisées.
|
||||
@@ -1353,12 +1400,12 @@
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Resources.NotIdentityRole">
|
||||
<summary>
|
||||
Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>..
|
||||
Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>..
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Resources.NotIdentityUser">
|
||||
<summary>
|
||||
Recherche une chaîne localisée semblable à AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>..
|
||||
Recherche une chaîne localisée semblable à AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>..
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:AspNetCore.Identity.MongoDbCore.Resources.RoleNotFound">
|
||||
@@ -1371,5 +1418,40 @@
|
||||
Recherche une chaîne localisée semblable à Value cannot be null or empty..
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions">
|
||||
<summary>
|
||||
Contains extension methods to <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> for adding MongoDb stores.
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores``1(Microsoft.AspNetCore.Identity.IdentityBuilder,MongoDbGenericRepository.IMongoDbContext)">
|
||||
<summary>
|
||||
Adds an MongoDb implementation of identity information stores.
|
||||
</summary>
|
||||
<typeparam name="TContext">The MongoDb database context to use.</typeparam>
|
||||
<param name="builder">The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</param>
|
||||
<param name="mongoDbContext">A mongoDbContext</param>
|
||||
<returns>The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</returns>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores``3(Microsoft.AspNetCore.Identity.IdentityBuilder,System.String,System.String)">
|
||||
<summary>
|
||||
Adds an MongoDb implementation of identity information stores.
|
||||
</summary>
|
||||
<typeparam name="TUser"></typeparam>
|
||||
<typeparam name="TRole"></typeparam>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="builder">The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</param>
|
||||
<param name="connectionString"></param>
|
||||
<param name="databaseName"></param>
|
||||
</member>
|
||||
<member name="M:Microsoft.Extensions.DependencyInjection.MongoDbIdentityBuilderExtensions.AddMongoDbStores``3(Microsoft.AspNetCore.Identity.IdentityBuilder,MongoDbGenericRepository.IMongoDbContext)">
|
||||
<summary>
|
||||
Adds an MongoDb implementation of identity information stores.
|
||||
</summary>
|
||||
<typeparam name="TUser"></typeparam>
|
||||
<typeparam name="TRole"></typeparam>
|
||||
<typeparam name="TKey"></typeparam>
|
||||
<param name="builder">The <see cref="T:Microsoft.AspNetCore.Identity.IdentityBuilder"/> instance this method extends.</param>
|
||||
<param name="mongoDbContext"></param>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -118,12 +118,12 @@
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="NotIdentityRole" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a role that derives from IdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from IdentityRole</comment>
|
||||
<value>AddMongoDbCoreStores can only be called with a role that derives from MongoIdentityRole<TKey, TUserRole, TRoleClaim>.</value>
|
||||
<comment>error when the role does not derive from MongoIdentityRole</comment>
|
||||
</data>
|
||||
<data name="NotIdentityUser" xml:space="preserve">
|
||||
<value>AddEntityFrameworkStores can only be called with a user that derives from IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from IdentityUser</comment>
|
||||
<value>AddMongoDbCoreStores can only be called with a user that derives from MongoIdentityUser<TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>.</value>
|
||||
<comment>error when the user does not derive from MongoIdentityUser</comment>
|
||||
</data>
|
||||
<data name="RoleNotFound" xml:space="preserve">
|
||||
<value>Role {0} does not exist.</value>
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.4" />
|
||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.5" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http" />
|
||||
|
||||
-150
@@ -1,150 +0,0 @@
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
{
|
||||
//public class CustomPocoTest : IClassFixture<MongoDatabaseFixture>
|
||||
//{
|
||||
// private readonly MongoDatabaseFixture _fixture;
|
||||
|
||||
// public CustomPocoTest(MongoDatabaseFixture fixture)
|
||||
// {
|
||||
// _fixture = fixture;
|
||||
// }
|
||||
|
||||
// public class User<TKey> where TKey : IEquatable<TKey>
|
||||
// {
|
||||
// public TKey Id { get; set; }
|
||||
// public string UserName { get; set; }
|
||||
// }
|
||||
|
||||
// public class CustomDbContext<TKey> : DbContext where TKey : IEquatable<TKey>
|
||||
// {
|
||||
// public CustomDbContext(DbContextOptions options) : base(options)
|
||||
// { }
|
||||
|
||||
// public DbSet<User<TKey>> Users { get; set; }
|
||||
|
||||
// }
|
||||
|
||||
// public CustomDbContext<TKey> GetContext<TKey>() where TKey : IEquatable<TKey>
|
||||
// {
|
||||
// return DbUtil.Create<CustomDbContext<TKey>>(_fixture.ConnectionString);
|
||||
// }
|
||||
|
||||
// public CustomDbContext<TKey> CreateContext<TKey>(bool delete = false) where TKey : IEquatable<TKey>
|
||||
// {
|
||||
// var db = GetContext<TKey>();
|
||||
// if (delete)
|
||||
// {
|
||||
// db.Database.EnsureDeleted();
|
||||
// }
|
||||
// db.Database.EnsureCreated();
|
||||
// return db;
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanUpdateNameGuid()
|
||||
// {
|
||||
// using (var db = CreateContext<Guid>(true))
|
||||
// {
|
||||
// var oldName = Guid.NewGuid().ToString();
|
||||
// var user = new User<Guid> { UserName = oldName, Id = Guid.NewGuid() };
|
||||
// db.Users.Add(user);
|
||||
// await db.SaveChangesAsync();
|
||||
// var newName = Guid.NewGuid().ToString();
|
||||
// user.UserName = newName;
|
||||
// await db.SaveChangesAsync();
|
||||
// Assert.Null(db.Users.SingleOrDefault(u => u.UserName == oldName));
|
||||
// Assert.Equal(user, db.Users.Single(u => u.UserName == newName));
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanUpdateNameString()
|
||||
// {
|
||||
// using (var db = CreateContext<string>(true))
|
||||
// {
|
||||
// var oldName = Guid.NewGuid().ToString();
|
||||
// var user = new User<string> { UserName = oldName, Id = Guid.NewGuid().ToString() };
|
||||
// db.Users.Add(user);
|
||||
// await db.SaveChangesAsync();
|
||||
// var newName = Guid.NewGuid().ToString();
|
||||
// user.UserName = newName;
|
||||
// await db.SaveChangesAsync();
|
||||
// Assert.Null(db.Users.SingleOrDefault(u => u.UserName == oldName));
|
||||
// Assert.Equal(user, db.Users.Single(u => u.UserName == newName));
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanCreateUserInt()
|
||||
// {
|
||||
// using (var db = CreateContext<int>(true))
|
||||
// {
|
||||
// var user = new User<int>();
|
||||
// db.Users.Add(user);
|
||||
// await db.SaveChangesAsync();
|
||||
// user.UserName = "Boo";
|
||||
// await db.SaveChangesAsync();
|
||||
// var fetch = db.Users.First(u => u.UserName == "Boo");
|
||||
// Assert.Equal(user, fetch);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanCreateUserIntViaSet()
|
||||
// {
|
||||
// using (var db = CreateContext<int>(true))
|
||||
// {
|
||||
// var user = new User<int>();
|
||||
// var users = db.Set<User<int>>();
|
||||
// users.Add(user);
|
||||
// await db.SaveChangesAsync();
|
||||
// user.UserName = "Boo";
|
||||
// await db.SaveChangesAsync();
|
||||
// var fetch = users.First(u => u.UserName == "Boo");
|
||||
// Assert.Equal(user, fetch);
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanUpdateNameInt()
|
||||
// {
|
||||
// using (var db = CreateContext<int>(true))
|
||||
// {
|
||||
// var oldName = Guid.NewGuid().ToString();
|
||||
// var user = new User<int> { UserName = oldName };
|
||||
// db.Users.Add(user);
|
||||
// await db.SaveChangesAsync();
|
||||
// var newName = Guid.NewGuid().ToString();
|
||||
// user.UserName = newName;
|
||||
// await db.SaveChangesAsync();
|
||||
// Assert.Null(db.Users.SingleOrDefault(u => u.UserName == oldName));
|
||||
// Assert.Equal(user, db.Users.Single(u => u.UserName == newName));
|
||||
// }
|
||||
// }
|
||||
|
||||
// [Fact]
|
||||
// public async Task CanUpdateNameIntWithSet()
|
||||
// {
|
||||
// using (var db = CreateContext<int>(true))
|
||||
// {
|
||||
// var oldName = Guid.NewGuid().ToString();
|
||||
// var user = new User<int> { UserName = oldName };
|
||||
// db.Set<User<int>>().Add(user);
|
||||
// await db.SaveChangesAsync();
|
||||
// var newName = Guid.NewGuid().ToString();
|
||||
// user.UserName = newName;
|
||||
// await db.SaveChangesAsync();
|
||||
// Assert.Null(db.Set<User<int>>().SingleOrDefault(u => u.UserName == oldName));
|
||||
// Assert.Equal(user, db.Set<User<int>>().Single(u => u.UserName == newName));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
+2
-4
@@ -2,7 +2,6 @@
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Security.Claims;
|
||||
@@ -14,7 +13,6 @@ using Microsoft.Extensions.Logging;
|
||||
using Xunit;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
using AspNetCore.Identity.MongoDbCore.Extensions;
|
||||
using AspNetCore.Identity.MongoDbCore;
|
||||
using MongoDB.Driver;
|
||||
using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
|
||||
using MongoDbGenericRepository;
|
||||
@@ -24,7 +22,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
{
|
||||
// TODO: Add test variation with non IdentityDbContext
|
||||
|
||||
public abstract class SqlStoreTestBase<TUser, TRole, TKey> : IdentitySpecificationTestBase<TUser, TRole, TKey>,
|
||||
public abstract class MongoDbStoreTestBase<TUser, TRole, TKey> : IdentitySpecificationTestBase<TUser, TRole, TKey>,
|
||||
IClassFixture<MongoDatabaseFixture<TUser, TRole, TKey>>
|
||||
where TUser : MongoIdentityUser<TKey>, new()
|
||||
where TRole : MongoIdentityRole<TKey>, new()
|
||||
@@ -32,7 +30,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
{
|
||||
private readonly MongoDatabaseFixture<TUser, TRole, TKey> _fixture;
|
||||
|
||||
protected SqlStoreTestBase(MongoDatabaseFixture<TUser, TRole, TKey> fixture)
|
||||
protected MongoDbStoreTestBase(MongoDatabaseFixture<TUser, TRole, TKey> fixture)
|
||||
{
|
||||
_fixture = fixture;
|
||||
}
|
||||
+1
-3
@@ -3,9 +3,7 @@
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
using AspNetCore.Identity.MongoDbCore;
|
||||
using MongoDbGenericRepository;
|
||||
using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
@@ -26,7 +24,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
}
|
||||
}
|
||||
|
||||
public class UserStoreGuidTest : SqlStoreTestBase<GuidUser, GuidRole, Guid>
|
||||
public class UserStoreGuidTest : MongoDbStoreTestBase<GuidUser, GuidRole, Guid>
|
||||
{
|
||||
public UserStoreGuidTest(MongoDatabaseFixture<GuidUser, GuidRole, Guid> fixture)
|
||||
: base(fixture)
|
||||
|
||||
+1
-3
@@ -2,8 +2,6 @@
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Xunit;
|
||||
using AspNetCore.Identity.MongoDbCore.Models;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
@@ -23,7 +21,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
}
|
||||
}
|
||||
|
||||
public class UserStoreIntTest : SqlStoreTestBase<IntUser, IntRole, int>
|
||||
public class UserStoreIntTest : MongoDbStoreTestBase<IntUser, IntRole, int>
|
||||
{
|
||||
public UserStoreIntTest(MongoDatabaseFixture<IntUser, IntRole, int> fixture)
|
||||
: base(fixture)
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
}
|
||||
}
|
||||
|
||||
public class UserStoreStringKeyTest : SqlStoreTestBase<StringUser, StringRole, string>
|
||||
public class UserStoreStringKeyTest : MongoDbStoreTestBase<StringUser, StringRole, string>
|
||||
{
|
||||
public UserStoreStringKeyTest(MongoDatabaseFixture<StringUser, StringRole, string> fixture)
|
||||
: base(fixture)
|
||||
|
||||
-1
@@ -222,7 +222,6 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
||||
{
|
||||
public IdentityUserWithGenerics() : base()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-165
@@ -1,165 +0,0 @@
|
||||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Data.Common;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace AspNetCore.Identity.MongoDbCore.Test.Utilities
|
||||
{
|
||||
//public class SqlServerTestStore : IDisposable
|
||||
//{
|
||||
// public const int CommandTimeout = 90;
|
||||
|
||||
// public static string CreateConnectionString(string name)
|
||||
// {
|
||||
// var connStrBuilder = new SqlConnectionStringBuilder(TestEnvironment.Config["Test:SqlServer:DefaultConnectionString"])
|
||||
// {
|
||||
// InitialCatalog = name
|
||||
// };
|
||||
|
||||
// return connStrBuilder.ConnectionString;
|
||||
// }
|
||||
|
||||
// public static SqlServerTestStore CreateScratch(bool createDatabase = true)
|
||||
// => new SqlServerTestStore(GetScratchDbName()).CreateTransient(createDatabase);
|
||||
|
||||
// private SqlConnection _connection;
|
||||
// private readonly string _name;
|
||||
// private bool _deleteDatabase;
|
||||
|
||||
// private SqlServerTestStore(string name)
|
||||
// {
|
||||
// _name = name;
|
||||
// }
|
||||
|
||||
// private static string GetScratchDbName()
|
||||
// {
|
||||
// string name;
|
||||
// do
|
||||
// {
|
||||
// name = "Scratch_" + Guid.NewGuid();
|
||||
// } while (DatabaseExists(name)
|
||||
// || DatabaseFilesExist(name));
|
||||
|
||||
// return name;
|
||||
// }
|
||||
|
||||
// private static void WaitForExists(SqlConnection connection)
|
||||
// {
|
||||
// var retryCount = 0;
|
||||
// while (true)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// connection.Open();
|
||||
|
||||
// connection.Close();
|
||||
|
||||
// return;
|
||||
// }
|
||||
// catch (SqlException e)
|
||||
// {
|
||||
// if (++retryCount >= 30
|
||||
// || (e.Number != 233 && e.Number != -2 && e.Number != 4060))
|
||||
// {
|
||||
// throw;
|
||||
// }
|
||||
|
||||
// SqlConnection.ClearPool(connection);
|
||||
|
||||
// Thread.Sleep(100);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// private SqlServerTestStore CreateTransient(bool createDatabase)
|
||||
// {
|
||||
// _connection = new SqlConnection(CreateConnectionString(_name));
|
||||
|
||||
// if (createDatabase)
|
||||
// {
|
||||
// using (var master = new SqlConnection(CreateConnectionString("master")))
|
||||
// {
|
||||
// master.Open();
|
||||
// using (var command = master.CreateCommand())
|
||||
// {
|
||||
// command.CommandTimeout = CommandTimeout;
|
||||
// command.CommandText = $"{Environment.NewLine}CREATE DATABASE [{_name}]";
|
||||
|
||||
// command.ExecuteNonQuery();
|
||||
|
||||
// WaitForExists(_connection);
|
||||
// }
|
||||
// }
|
||||
// _connection.Open();
|
||||
// }
|
||||
|
||||
// _deleteDatabase = true;
|
||||
// return this;
|
||||
// }
|
||||
|
||||
// private static bool DatabaseExists(string name)
|
||||
// {
|
||||
// using (var master = new SqlConnection(CreateConnectionString("master")))
|
||||
// {
|
||||
// master.Open();
|
||||
|
||||
// using (var command = master.CreateCommand())
|
||||
// {
|
||||
// command.CommandTimeout = CommandTimeout;
|
||||
// command.CommandText = $@"SELECT COUNT(*) FROM sys.databases WHERE name = N'{name}'";
|
||||
|
||||
// return (int) command.ExecuteScalar() > 0;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// private static bool DatabaseFilesExist(string name)
|
||||
// {
|
||||
// var userFolder = Environment.GetEnvironmentVariable("USERPROFILE") ??
|
||||
// Environment.GetEnvironmentVariable("HOME");
|
||||
// return userFolder != null
|
||||
// && (File.Exists(Path.Combine(userFolder, name + ".mdf"))
|
||||
// || File.Exists(Path.Combine(userFolder, name + "_log.ldf")));
|
||||
// }
|
||||
|
||||
// private void DeleteDatabase(string name)
|
||||
// {
|
||||
// using (var master = new SqlConnection(CreateConnectionString("master")))
|
||||
// {
|
||||
// master.Open();
|
||||
|
||||
// using (var command = master.CreateCommand())
|
||||
// {
|
||||
// command.CommandTimeout = CommandTimeout;
|
||||
// // Query will take a few seconds if (and only if) there are active connections
|
||||
|
||||
// // SET SINGLE_USER will close any open connections that would prevent the drop
|
||||
// command.CommandText
|
||||
// = string.Format(@"IF EXISTS (SELECT * FROM sys.databases WHERE name = N'{0}')
|
||||
// BEGIN
|
||||
// ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
|
||||
// DROP DATABASE [{0}];
|
||||
// END", name);
|
||||
|
||||
// command.ExecuteNonQuery();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// public DbConnection Connection => _connection;
|
||||
|
||||
// public void Dispose()
|
||||
// {
|
||||
// _connection.Dispose();
|
||||
|
||||
// if (_deleteDatabase)
|
||||
// {
|
||||
// DeleteDatabase(_name);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user