diff --git a/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj b/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj index 9ee5219..8aa2573 100644 --- a/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj +++ b/sample/MongoIdentitySample.Mvc/MongoIdentitySample.Mvc.csproj @@ -8,7 +8,7 @@ - + diff --git a/src/AspNetCore.Identity.MongoDbCore.csproj b/src/AspNetCore.Identity.MongoDbCore.csproj index ce62933..eeda372 100644 --- a/src/AspNetCore.Identity.MongoDbCore.csproj +++ b/src/AspNetCore.Identity.MongoDbCore.csproj @@ -17,7 +17,7 @@ - + diff --git a/src/AspNetCore.Identity.MongoDbCore.nuspec b/src/AspNetCore.Identity.MongoDbCore.nuspec index cfa33ef..3490dd3 100644 --- a/src/AspNetCore.Identity.MongoDbCore.nuspec +++ b/src/AspNetCore.Identity.MongoDbCore.nuspec @@ -2,7 +2,7 @@ AspNetCore.Identity.MongoDbCore - 1.0.7 + 1.0.8 AspNetCore.Identity.MongoDbCore Alexandre Spieser Alexandre Spieser @@ -10,14 +10,14 @@ https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore false A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0. - MongoDB 3.6 Support, Identity 2.0.1 upgrade. - Copyright 2017 (c) Alexandre Spieser. All rights reserved. + Added support for documents with an Id of type ObjectId. + Copyright 2018 (c) Alexandre Spieser. All rights reserved. aspnetcore mongo mongodb identity membership - + diff --git a/src/Extensions/StringExtensions.cs b/src/Extensions/StringExtensions.cs new file mode 100644 index 0000000..f9b3300 --- /dev/null +++ b/src/Extensions/StringExtensions.cs @@ -0,0 +1,31 @@ +using MongoDB.Bson; +using System.ComponentModel; + +namespace AspNetCore.Identity.MongoDbCore.Extensions +{ + /// + /// A set of extensions for string. + /// + public static class StringExtensions + { + /// + /// Converts the provided to a strongly typed key object. + /// + /// + /// + /// + public static TKey ToTKey(this string id) + { + if (id == null) + { + return default(TKey); + } + var typeOfKey = typeof(TKey); + if (typeOfKey.Name != "ObjectId") + { + return (TKey)TypeDescriptor.GetConverter(typeOfKey).ConvertFromInvariantString(id); + } + return (TKey)(object)(new ObjectId(id)); + } + } +} diff --git a/src/Models/MongoIdentityRole.cs b/src/Models/MongoIdentityRole.cs index 3ee76a7..698a1db 100644 --- a/src/Models/MongoIdentityRole.cs +++ b/src/Models/MongoIdentityRole.cs @@ -2,6 +2,7 @@ using AspNetCore.Identity.MongoDbCore.Interfaces; using Microsoft.AspNetCore.Identity; using MongoDbGenericRepository.Models; +using MongoDbGenericRepository.Utils; using System; using System.Collections.Generic; @@ -56,33 +57,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models public class MongoIdentityRole : IdentityRole, IDocument, IClaimHolder where TKey : IEquatable { - - private void InitializeFields() - { - Version = 1; - Claims = new List(); - Guid guidValue = Guid.NewGuid(); - var idTypeName = typeof(TKey).Name; - switch (idTypeName) - { - case "Guid": - Id = (TKey)(object)guidValue; - break; - case "Int16": - Id = (TKey)(object)GlobalVariables.Random.Next(1, short.MaxValue); - break; - case "Int32": - Id = (TKey)(object)GlobalVariables.Random.Next(1, int.MaxValue); - break; - case "Int64": - Id = (TKey)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue)); - break; - case "String": - Id = (TKey)(object)guidValue.ToString(); - break; - } - } - /// /// The constructor for a /// @@ -101,6 +75,16 @@ namespace AspNetCore.Identity.MongoDbCore.Models InitializeFields(); } + /// + /// Initialize the field of the MongoIdentityRole + /// + protected virtual void InitializeFields() + { + Version = 1; + Claims = new List(); + Id = IdGenerator.GetId(); + } + /// /// The constructor for a , taking a role name and a primary key value. /// diff --git a/src/Models/MongoIdentityUser.cs b/src/Models/MongoIdentityUser.cs index c983dea..bec8759 100644 --- a/src/Models/MongoIdentityUser.cs +++ b/src/Models/MongoIdentityUser.cs @@ -6,6 +6,7 @@ using MongoDB.Driver; using AspNetCore.Identity.MongoDbCore.Interfaces; using Microsoft.AspNetCore.Identity; using AspNetCore.Identity.MongoDbCore.Extensions; +using MongoDbGenericRepository.Utils; namespace AspNetCore.Identity.MongoDbCore.Models { @@ -134,7 +135,19 @@ namespace AspNetCore.Identity.MongoDbCore.Models UserName = userName ?? throw new ArgumentNullException(nameof(userName)); SetVersion(1); InitializeFields(); + } + + /// + /// Initialize the field of the MongoIdentityUser + /// + protected virtual void InitializeFields() + { + CreatedOn = DateTime.UtcNow; + Claims = new List(); + Logins = new List(); Roles = new List(); + Tokens = new List(); + Id = IdGenerator.GetId(); } /// @@ -166,7 +179,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models return false; } - /// /// Add a role to the user. /// @@ -266,7 +278,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models #region Token Management - /// /// Sets the token to a new value. /// @@ -360,36 +371,5 @@ namespace AspNetCore.Identity.MongoDbCore.Models #endregion Token Management - private void InitializeFields() - { - CreatedOn = DateTime.UtcNow; - Claims = new List(); - Logins = new List(); - Roles = new List(); - Tokens = new List(); - Guid guidValue = Guid.NewGuid(); - - var idTypeName = typeof(TKey).Name; - switch (idTypeName) - { - case "Guid": - Id = (TKey)(object)guidValue; - break; - case "Int16": - Id = (TKey)(object)GlobalVariables.Random.Next(1, short.MaxValue); - break; - case "Int32": - Id = (TKey)(object)GlobalVariables.Random.Next(1, int.MaxValue); - break; - case "Int64": - Id = (TKey)(object)(GlobalVariables.Random.NextLong(1, long.MaxValue)); - break; - case "String": - Id = (TKey)(object)guidValue.ToString(); - break; - } - - } - } } \ No newline at end of file diff --git a/src/MongoRoleStore.cs b/src/MongoRoleStore.cs index bfe9ed3..bfed4dc 100644 --- a/src/MongoRoleStore.cs +++ b/src/MongoRoleStore.cs @@ -123,6 +123,16 @@ namespace AspNetCore.Identity.MongoDbCore } } + /// + /// A navigation property for the roles the store contains. + /// + public virtual IQueryable Roles => RolesCollection.AsQueryable(); + + /// + /// A navigation property for the roles the store contains. + /// + public virtual IMongoCollection RolesCollection => Context.GetCollection(); + /// /// Gets or sets the for any error that occurred with the current operation. /// @@ -170,8 +180,7 @@ namespace AspNetCore.Identity.MongoDbCore } var oldStamp = role.ConcurrencyStamp; role.ConcurrencyStamp = Guid.NewGuid().ToString(); - var collection = MongoRepository.Context.GetCollection(); - var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(role.Id) + var updateRes = await RolesCollection.ReplaceOneAsync(x => x.Id.Equals(role.Id) && x.ConcurrencyStamp.Equals(oldStamp), role); if (updateRes.ModifiedCount == 0) @@ -197,8 +206,7 @@ namespace AspNetCore.Identity.MongoDbCore } var oldStamp = role.ConcurrencyStamp; role.ConcurrencyStamp = Guid.NewGuid().ToString(); - var collection = MongoRepository.Context.GetCollection(); - var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(role.Id) + var deleteRes = await RolesCollection.DeleteOneAsync(x => x.Id.Equals(role.Id) && x.ConcurrencyStamp.Equals(oldStamp)); if (deleteRes.DeletedCount == 0) { @@ -272,11 +280,7 @@ namespace AspNetCore.Identity.MongoDbCore /// An instance of representing the provided . public virtual TKey ConvertIdFromString(string id) { - if (id == null) - { - return default(TKey); - } - return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id); + return id.ToTKey(); } /// @@ -448,10 +452,7 @@ namespace AspNetCore.Identity.MongoDbCore } } - /// - /// A navigation property for the roles the store contains. - /// - public virtual IQueryable Roles => Context.GetCollection().AsQueryable(); + /// /// Creates a entity representing a role claim. diff --git a/src/MongoUserOnlyStore.cs b/src/MongoUserOnlyStore.cs index 571d918..f99adb0 100644 --- a/src/MongoUserOnlyStore.cs +++ b/src/MongoUserOnlyStore.cs @@ -118,7 +118,7 @@ namespace AspNetCore.Identity.MongoDbCore } } - private IMongoCollection UsersSet { get { return Context.GetCollection(); } } + private IMongoCollection UsersCollection { get { return Context.GetCollection(); } } /// /// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called. @@ -150,7 +150,7 @@ namespace AspNetCore.Identity.MongoDbCore { throw new ArgumentNullException(nameof(user)); } - await UsersSet.InsertOneAsync(user); + await UsersCollection.InsertOneAsync(user); await SaveChanges(cancellationToken); return IdentityResult.Success; } @@ -171,8 +171,7 @@ namespace AspNetCore.Identity.MongoDbCore } var oldStamp = user.ConcurrencyStamp; user.ConcurrencyStamp = Guid.NewGuid().ToString(); - var collection = MongoRepository.Context.GetCollection(); - var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id) + var updateRes = await UsersCollection.ReplaceOneAsync(x => x.Id.Equals(user.Id) && x.ConcurrencyStamp.Equals(oldStamp), user); if(updateRes.ModifiedCount == 0) @@ -202,8 +201,7 @@ namespace AspNetCore.Identity.MongoDbCore user.Tokens.Clear(); var oldStamp = user.ConcurrencyStamp; user.ConcurrencyStamp = Guid.NewGuid().ToString(); - var collection = MongoRepository.Context.GetCollection(); - var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(user.Id) + var deleteRes = await UsersCollection.DeleteOneAsync(x => x.Id.Equals(user.Id) && x.ConcurrencyStamp.Equals(oldStamp)); if (deleteRes.DeletedCount == 0) { @@ -248,7 +246,7 @@ namespace AspNetCore.Identity.MongoDbCore /// public override IQueryable Users { - get { return UsersSet.AsQueryable(); } + get { return UsersCollection.AsQueryable(); } } /// @@ -539,8 +537,7 @@ namespace AspNetCore.Identity.MongoDbCore } var filter = Builders.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value) && userClaims.Type.Equals(claim.Type)); - var collection = MongoRepository.Context.GetCollection(); - var cursor = collection.Find(filter); + var cursor = UsersCollection.Find(filter); var res = await cursor.ToListAsync(); return res; } diff --git a/src/MongoUserStore.cs b/src/MongoUserStore.cs index 3fa714a..be00f92 100644 --- a/src/MongoUserStore.cs +++ b/src/MongoUserStore.cs @@ -14,6 +14,8 @@ using AspNetCore.Identity.MongoDbCore.Extensions; using AspNetCore.Identity.MongoDbCore.Models; using AspNetCore.Identity.MongoDbCore.Infrastructure; using Microsoft.AspNetCore.Identity; +using System.ComponentModel; +using MongoDB.Bson; namespace AspNetCore.Identity.MongoDbCore { @@ -130,21 +132,29 @@ namespace AspNetCore.Identity.MongoDbCore /// private static TContext Context { get; set; } + private static object MongoRepositoryInitializationLock = new object(); private static IMongoRepository _mongoRepository; private static IMongoRepository MongoRepository { get { + // double checked locking to prevent race to initialize the repository in multithreaded environment. if (_mongoRepository == null) { - _mongoRepository = new MongoRepository(Context); + lock (MongoRepositoryInitializationLock) + { + if (_mongoRepository == null) + { + _mongoRepository = new MongoRepository(Context); + } + } } return _mongoRepository; } } - private IMongoCollection UsersSet { get { return Context.GetCollection(); } } - private IMongoCollection Roles { get { return Context.GetCollection(); } } + private IMongoCollection UsersCollection { get { return Context.GetCollection(); } } + private IMongoCollection RolesCollection { get { return Context.GetCollection(); } } /// /// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called. @@ -176,7 +186,7 @@ namespace AspNetCore.Identity.MongoDbCore { throw new ArgumentNullException(nameof(user)); } - await UsersSet.InsertOneAsync(user); + await UsersCollection.InsertOneAsync(user); await SaveChanges(cancellationToken); return IdentityResult.Success; } @@ -197,11 +207,11 @@ namespace AspNetCore.Identity.MongoDbCore } var oldStamp = user.ConcurrencyStamp; user.ConcurrencyStamp = Guid.NewGuid().ToString(); - var collection = MongoRepository.Context.GetCollection(); - var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id) - && x.ConcurrencyStamp.Equals(oldStamp), + var collection = MongoRepository.Context.GetCollection(); + var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id) + && x.ConcurrencyStamp.Equals(oldStamp), user); - if(updateRes.ModifiedCount == 0) + if (updateRes.ModifiedCount == 0) { return IdentityResult.Failed(ErrorDescriber.ConcurrencyFailure()); } @@ -228,8 +238,7 @@ namespace AspNetCore.Identity.MongoDbCore user.Tokens.Clear(); var oldStamp = user.ConcurrencyStamp; user.ConcurrencyStamp = Guid.NewGuid().ToString(); - var collection = MongoRepository.Context.GetCollection(); - var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(user.Id) + var deleteRes = await UsersCollection.DeleteOneAsync(x => x.Id.Equals(user.Id) && x.ConcurrencyStamp.Equals(oldStamp)); if (deleteRes.DeletedCount == 0) { @@ -254,6 +263,16 @@ namespace AspNetCore.Identity.MongoDbCore return MongoRepository.GetByIdAsync(id); } + /// + /// Converts the provided to a strongly typed key object. + /// + /// The id to convert. + /// An instance of representing the provided . + public override TKey ConvertIdFromString(string id) + { + return id.ToTKey(); + } + /// /// Finds and returns a user, if any, who has the specified normalized user name. /// @@ -274,7 +293,7 @@ namespace AspNetCore.Identity.MongoDbCore /// public override IQueryable Users { - get { return UsersSet.AsQueryable(); } + get { return UsersCollection.AsQueryable(); } } /// @@ -470,12 +489,12 @@ namespace AspNetCore.Identity.MongoDbCore } #pragma warning disable CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone - /// - /// Get the claims associated with the specified as an asynchronous operation. - /// - /// The user whose claims should be retrieved. - /// The used to propagate notifications that the operation should be canceled. - /// A that contains the claims granted to a user. + /// + /// Get the claims associated with the specified as an asynchronous operation. + /// + /// The user whose claims should be retrieved. + /// The used to propagate notifications that the operation should be canceled. + /// A that contains the claims granted to a user. public async override Task> GetClaimsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) #pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone { @@ -610,14 +629,14 @@ namespace AspNetCore.Identity.MongoDbCore } #pragma warning disable CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone - /// - /// Removes the given from the specified . - /// - /// The user to remove the login from. - /// The login to remove from the user. - /// The key provided by the to identify a user. - /// The used to propagate notifications that the operation should be canceled. - /// The that represents the asynchronous operation. + /// + /// Removes the given from the specified . + /// + /// The user to remove the login from. + /// The login to remove from the user. + /// The key provided by the to identify a user. + /// The used to propagate notifications that the operation should be canceled. + /// The that represents the asynchronous operation. public override async Task RemoveLoginAsync(TUser user, string loginProvider, string providerKey, #pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone CancellationToken cancellationToken = default(CancellationToken)) @@ -636,14 +655,14 @@ namespace AspNetCore.Identity.MongoDbCore } #pragma warning disable CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone - /// - /// Retrieves the associated logins for the specified . - /// - /// The user whose associated logins to retrieve. - /// The used to propagate notifications that the operation should be canceled. - /// - /// The for the asynchronous operation, containing a list of for the specified , if any. - /// + /// + /// Retrieves the associated logins for the specified . + /// + /// The user whose associated logins to retrieve. + /// The used to propagate notifications that the operation should be canceled. + /// + /// The for the asynchronous operation, containing a list of for the specified , if any. + /// public async override Task> GetLoginsAsync(TUser user, CancellationToken cancellationToken = default(CancellationToken)) #pragma warning restore CS1998 // Cette méthode async n'a pas d'opérateur 'await' et elle s'exécutera de façon synchrone { @@ -711,8 +730,7 @@ namespace AspNetCore.Identity.MongoDbCore } var filter = Builders.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value) && userClaims.Type.Equals(claim.Type)); - var collection = MongoRepository.Context.GetCollection(); - var cursor = collection.Find(filter); + var cursor = UsersCollection.Find(filter); var res = await cursor.ToListAsync(); return res; } diff --git a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.deps.json b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.deps.json index 4e83033..a5e6a14 100644 --- a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.deps.json +++ b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.deps.json @@ -1,7 +1,7 @@ { "runtimeTarget": { "name": ".NETCoreApp,Version=v2.0", - "signature": "38e5f0ca5f25fc12f74d4c5d8051381123909848" + "signature": "38b2f87cafd1a2fa8c7bd3268841c3cd7abe472b" }, "compilationOptions": {}, "targets": { @@ -11,7 +11,7 @@ "Microsoft.AspNetCore.Identity": "2.0.1", "Microsoft.Extensions.Identity.Stores": "2.0.1", "MongoDB.Driver": "2.5.0", - "MongoDbGenericRepository": "1.3.4" + "MongoDbGenericRepository": "1.3.6" }, "runtime": { "AspNetCore.Identity.MongoDbCore.dll": {} @@ -359,7 +359,7 @@ "lib/netstandard1.5/MongoDB.Driver.Core.dll": {} } }, - "MongoDbGenericRepository/1.3.4": { + "MongoDbGenericRepository/1.3.6": { "dependencies": { "MongoDB.Driver": "2.5.0" }, @@ -1462,12 +1462,12 @@ "path": "mongodb.driver.core/2.5.0", "hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512" }, - "MongoDbGenericRepository/1.3.4": { + "MongoDbGenericRepository/1.3.6": { "type": "package", "serviceable": true, - "sha512": "sha512-nVtq9UGq6e8I61D1Fc1HIvh4qVA92IkfpcmrNXgG2141qBOpY7U0FbKlz+NOqiJoopY/ejhTBE3QbicsxsoOeg==", - "path": "mongodbgenericrepository/1.3.4", - "hashPath": "mongodbgenericrepository.1.3.4.nupkg.sha512" + "sha512": "sha512-bm4Q5RDLqt6rRZJTDiWvQpHOJ3ACxfELqg0kiZO8dyb7xMEqPQC7urpuLKMpDUmnE/pMBuXe6Pmy9TyTksDbdg==", + "path": "mongodbgenericrepository/1.3.6", + "hashPath": "mongodbgenericrepository.1.3.6.nupkg.sha512" }, "runtime.native.System/4.3.0": { "type": "package", diff --git a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll index eee24d0..c395fd0 100644 Binary files a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll and b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.dll differ diff --git a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml index e42217d..8ee2e9a 100644 --- a/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml +++ b/src/lib/netcoreapp2.0/AspNetCore.Identity.MongoDbCore.xml @@ -130,6 +130,19 @@ A configuration object of the AspNetCore.Identity.MongoDbCore package. An object representing a MongoDb connection. + + + A set of extensions for string. + + + + + Converts the provided to a strongly typed key object. + + + + + A class holding global variables. @@ -308,6 +321,11 @@ The name of the role. + + + Initialize the field of the MongoIdentityRole + + The constructor for a , taking a role name and a primary key value. @@ -425,6 +443,11 @@ The name of the user. + + + Initialize the field of the MongoIdentityUser + + Sets the version of the schema for the document. @@ -597,6 +620,16 @@ Gets the database context for this store. + + + A navigation property for the roles the store contains. + + + + + A navigation property for the roles the store contains. + + Gets or sets the for any error that occurred with the current operation. @@ -742,11 +775,6 @@ The used to propagate notifications that the operation should be canceled. The that represents the asynchronous operation. - - - A navigation property for the roles the store contains. - - Creates a entity representing a role claim. @@ -1360,6 +1388,13 @@ The that represents the asynchronous operation, containing the user matching the specified if it exists. + + + Converts the provided to a strongly typed key object. + + The id to convert. + An instance of representing the provided . + Finds and returns a user, if any, who has the specified normalized user name. diff --git a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.deps.json b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.deps.json index 3d8faa0..e59009d 100644 --- a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.deps.json +++ b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.deps.json @@ -1,7 +1,7 @@ { "runtimeTarget": { "name": ".NETStandard,Version=v2.0/", - "signature": "9926fc91f43fdc960144838c1bcb58195d97fdd2" + "signature": "777efc9083cc946975cf0e3ebd09810483543683" }, "compilationOptions": {}, "targets": { @@ -12,7 +12,7 @@ "Microsoft.AspNetCore.Identity": "2.0.1", "Microsoft.Extensions.Identity.Stores": "2.0.1", "MongoDB.Driver": "2.5.0", - "MongoDbGenericRepository": "1.3.4", + "MongoDbGenericRepository": "1.3.6", "NETStandard.Library": "2.0.1" }, "runtime": { @@ -360,7 +360,7 @@ "lib/netstandard1.5/MongoDB.Driver.Core.dll": {} } }, - "MongoDbGenericRepository/1.3.4": { + "MongoDbGenericRepository/1.3.6": { "dependencies": { "MongoDB.Driver": "2.5.0" }, @@ -1427,12 +1427,12 @@ "path": "mongodb.driver.core/2.5.0", "hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512" }, - "MongoDbGenericRepository/1.3.4": { + "MongoDbGenericRepository/1.3.6": { "type": "package", "serviceable": true, - "sha512": "sha512-nVtq9UGq6e8I61D1Fc1HIvh4qVA92IkfpcmrNXgG2141qBOpY7U0FbKlz+NOqiJoopY/ejhTBE3QbicsxsoOeg==", - "path": "mongodbgenericrepository/1.3.4", - "hashPath": "mongodbgenericrepository.1.3.4.nupkg.sha512" + "sha512": "sha512-bm4Q5RDLqt6rRZJTDiWvQpHOJ3ACxfELqg0kiZO8dyb7xMEqPQC7urpuLKMpDUmnE/pMBuXe6Pmy9TyTksDbdg==", + "path": "mongodbgenericrepository/1.3.6", + "hashPath": "mongodbgenericrepository.1.3.6.nupkg.sha512" }, "NETStandard.Library/2.0.1": { "type": "package", diff --git a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll index a6fa8aa..0b534ee 100644 Binary files a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll and b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.dll differ diff --git a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml index e42217d..8ee2e9a 100644 --- a/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml +++ b/src/lib/netstandard2.0/AspNetCore.Identity.MongoDbCore.xml @@ -130,6 +130,19 @@ A configuration object of the AspNetCore.Identity.MongoDbCore package. An object representing a MongoDb connection. + + + A set of extensions for string. + + + + + Converts the provided to a strongly typed key object. + + + + + A class holding global variables. @@ -308,6 +321,11 @@ The name of the role. + + + Initialize the field of the MongoIdentityRole + + The constructor for a , taking a role name and a primary key value. @@ -425,6 +443,11 @@ The name of the user. + + + Initialize the field of the MongoIdentityUser + + Sets the version of the schema for the document. @@ -597,6 +620,16 @@ Gets the database context for this store. + + + A navigation property for the roles the store contains. + + + + + A navigation property for the roles the store contains. + + Gets or sets the for any error that occurred with the current operation. @@ -742,11 +775,6 @@ The used to propagate notifications that the operation should be canceled. The that represents the asynchronous operation. - - - A navigation property for the roles the store contains. - - Creates a entity representing a role claim. @@ -1360,6 +1388,13 @@ The that represents the asynchronous operation, containing the user matching the specified if it exists. + + + Converts the provided to a strongly typed key object. + + The id to convert. + An instance of representing the provided . + Finds and returns a user, if any, who has the specified normalized user name. diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj index 46233e5..b8099f0 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.IntegrationTests.csproj @@ -7,7 +7,7 @@ - + @@ -21,7 +21,7 @@ - + diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs index 68a7918..8316752 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/MongoDbStoreTestBase.cs @@ -162,7 +162,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test private IQueryable GetQueryable() { - return Container.MongoRepository.Context.GetCollection().AsQueryable(); + return Container.MongoRepository.Context.GetCollection().AsQueryable(); } [Fact] diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreOnlyUsersTestBase.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreOnlyUsersTestBase.cs index cffdb8e..52abf72 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreOnlyUsersTestBase.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/SqlStoreOnlyUsersTestBase.cs @@ -87,7 +87,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test private IQueryable GetQueryable() { - return Container.MongoRepository.Context.GetCollection().AsQueryable(); + return Container.MongoRepository.Context.GetCollection().AsQueryable(); } [Fact] diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreObjectIdKeyTest.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreObjectIdKeyTest.cs new file mode 100644 index 0000000..ba1a97c --- /dev/null +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/UserStoreObjectIdKeyTest.cs @@ -0,0 +1,56 @@ +// 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 Microsoft.Extensions.DependencyInjection; +using AspNetCore.Identity.MongoDbCore.Models; +using MongoDbGenericRepository; +using AspNetCore.Identity.MongoDbCore.IntegrationTests.Infrastructure; +using Microsoft.AspNetCore.Identity; +using MongoDB.Bson; + +namespace AspNetCore.Identity.MongoDbCore.Test +{ + public class ObjectIdUser : MongoIdentityUser + { + public ObjectIdUser() : base() + { + } + } + + public class ObjectIdRole : MongoIdentityRole + { + public ObjectIdRole() : base() + { + } + } + + public class UserStoreObjectIdTest : MongoDbStoreTestBase + { + public UserStoreObjectIdTest(MongoDatabaseFixture fixture) + : base(fixture) + { + } + + public class ApplicationUserStore : MongoUserStore + { + public ApplicationUserStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { } + } + + public class ApplicationRoleStore : MongoRoleStore + { + public ApplicationRoleStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { } + } + + protected override void AddUserStore(IServiceCollection services, object context = null) + { + services.AddSingleton>(new ApplicationUserStore(Container.MongoRepository.Context)); + } + + protected override void AddRoleStore(IServiceCollection services, object context = null) + { + services.AddSingleton>(new ApplicationRoleStore(Container.MongoRepository.Context)); + } + + } +} \ No newline at end of file diff --git a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/MongoDatabaseFixture.cs b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/MongoDatabaseFixture.cs index ab42c7e..9ce8b29 100644 --- a/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/MongoDatabaseFixture.cs +++ b/test/AspNetCore.Identity.MongoDbCore.IntegrationTests/AspNetCore.Identity.MongoDbCore.Test/Utilities/MongoDatabaseFixture.cs @@ -31,7 +31,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test var userIds = UsersToDelete.ToList().Select(e => e.Id); if (userIds.Any()) { - Context.GetCollection().DeleteMany(e => userIds.Contains(e.Id)); + Context.GetCollection().DeleteMany(e => userIds.Contains(e.Id)); } } } @@ -57,12 +57,12 @@ namespace AspNetCore.Identity.MongoDbCore.Test var userIds = UsersToDelete.ToList().Select(e => e.Id); if (userIds.Any()) { - Context.GetCollection().DeleteMany(e => userIds.Contains(e.Id)); + Context.GetCollection().DeleteMany(e => userIds.Contains(e.Id)); } var roleIds = RolesToDelete.ToList().Select(e => e.Id); if (roleIds.Any()) { - Context.GetCollection().DeleteMany(e => roleIds.Contains(e.Id)); + Context.GetCollection().DeleteMany(e => roleIds.Contains(e.Id)); } } }