Add support for documents with and Id of type ObjectId.
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.7" />
|
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.8" />
|
||||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.0.1" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
||||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.4" />
|
<PackageReference Include="MongoDbGenericRepository" Version="1.3.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<package >
|
<package >
|
||||||
<metadata>
|
<metadata>
|
||||||
<id>AspNetCore.Identity.MongoDbCore</id>
|
<id>AspNetCore.Identity.MongoDbCore</id>
|
||||||
<version>1.0.7</version>
|
<version>1.0.8</version>
|
||||||
<title>AspNetCore.Identity.MongoDbCore</title>
|
<title>AspNetCore.Identity.MongoDbCore</title>
|
||||||
<authors>Alexandre Spieser</authors>
|
<authors>Alexandre Spieser</authors>
|
||||||
<owners>Alexandre Spieser</owners>
|
<owners>Alexandre Spieser</owners>
|
||||||
@@ -10,14 +10,14 @@
|
|||||||
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
|
<projectUrl>https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore</projectUrl>
|
||||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||||
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.</description>
|
<description>A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0.</description>
|
||||||
<releaseNotes>MongoDB 3.6 Support, Identity 2.0.1 upgrade.</releaseNotes>
|
<releaseNotes>Added support for documents with an Id of type ObjectId.</releaseNotes>
|
||||||
<copyright>Copyright 2017 (c) Alexandre Spieser. All rights reserved.</copyright>
|
<copyright>Copyright 2018 (c) Alexandre Spieser. All rights reserved.</copyright>
|
||||||
<tags>aspnetcore mongo mongodb identity membership</tags>
|
<tags>aspnetcore mongo mongodb identity membership</tags>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency id="Microsoft.AspNetCore.Identity" version="2.0.1" />
|
<dependency id="Microsoft.AspNetCore.Identity" version="2.0.1" />
|
||||||
<dependency id="Microsoft.Extensions.Identity.Stores" version="2.0.1" />
|
<dependency id="Microsoft.Extensions.Identity.Stores" version="2.0.1" />
|
||||||
<dependency id="MongoDB.Driver" version="2.5.0" />
|
<dependency id="MongoDB.Driver" version="2.5.0" />
|
||||||
<dependency id="MongoDbGenericRepository" version="1.3.4" />
|
<dependency id="MongoDbGenericRepository" version="1.3.6" />
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</metadata>
|
</metadata>
|
||||||
<files>
|
<files>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
using MongoDB.Bson;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace AspNetCore.Identity.MongoDbCore.Extensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A set of extensions for string.
|
||||||
|
/// </summary>
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TKey"></typeparam>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static TKey ToTKey<TKey>(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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using MongoDbGenericRepository.Models;
|
using MongoDbGenericRepository.Models;
|
||||||
|
using MongoDbGenericRepository.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -56,33 +57,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
public class MongoIdentityRole<TKey> : IdentityRole<TKey>, IDocument<TKey>, IClaimHolder
|
public class MongoIdentityRole<TKey> : IdentityRole<TKey>, IDocument<TKey>, IClaimHolder
|
||||||
where TKey : IEquatable<TKey>
|
where TKey : IEquatable<TKey>
|
||||||
{
|
{
|
||||||
|
|
||||||
private void InitializeFields()
|
|
||||||
{
|
|
||||||
Version = 1;
|
|
||||||
Claims = new List<MongoClaim>();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>
|
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -101,6 +75,16 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
InitializeFields();
|
InitializeFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the field of the MongoIdentityRole
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void InitializeFields()
|
||||||
|
{
|
||||||
|
Version = 1;
|
||||||
|
Claims = new List<MongoClaim>();
|
||||||
|
Id = IdGenerator.GetId<TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name and a primary key value.
|
/// The constructor for a <see cref="MongoIdentityRole{TKey}"/>, taking a role name and a primary key value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using MongoDB.Driver;
|
|||||||
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
using AspNetCore.Identity.MongoDbCore.Interfaces;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
using AspNetCore.Identity.MongoDbCore.Extensions;
|
using AspNetCore.Identity.MongoDbCore.Extensions;
|
||||||
|
using MongoDbGenericRepository.Utils;
|
||||||
|
|
||||||
namespace AspNetCore.Identity.MongoDbCore.Models
|
namespace AspNetCore.Identity.MongoDbCore.Models
|
||||||
{
|
{
|
||||||
@@ -134,7 +135,19 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
UserName = userName ?? throw new ArgumentNullException(nameof(userName));
|
UserName = userName ?? throw new ArgumentNullException(nameof(userName));
|
||||||
SetVersion(1);
|
SetVersion(1);
|
||||||
InitializeFields();
|
InitializeFields();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initialize the field of the MongoIdentityUser
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void InitializeFields()
|
||||||
|
{
|
||||||
|
CreatedOn = DateTime.UtcNow;
|
||||||
|
Claims = new List<MongoClaim>();
|
||||||
|
Logins = new List<UserLoginInfo>();
|
||||||
Roles = new List<TKey>();
|
Roles = new List<TKey>();
|
||||||
|
Tokens = new List<Token>();
|
||||||
|
Id = IdGenerator.GetId<TKey>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -166,7 +179,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a role to the user.
|
/// Add a role to the user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -266,7 +278,6 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
|
|
||||||
#region Token Management
|
#region Token Management
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the token to a new value.
|
/// Sets the token to a new value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -360,36 +371,5 @@ namespace AspNetCore.Identity.MongoDbCore.Models
|
|||||||
|
|
||||||
#endregion Token Management
|
#endregion Token Management
|
||||||
|
|
||||||
private void InitializeFields()
|
|
||||||
{
|
|
||||||
CreatedOn = DateTime.UtcNow;
|
|
||||||
Claims = new List<MongoClaim>();
|
|
||||||
Logins = new List<UserLoginInfo>();
|
|
||||||
Roles = new List<TKey>();
|
|
||||||
Tokens = new List<Token>();
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-13
@@ -123,6 +123,16 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A navigation property for the roles the store contains.
|
||||||
|
/// </summary>
|
||||||
|
public virtual IQueryable<TRole> Roles => RolesCollection.AsQueryable();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A navigation property for the roles the store contains.
|
||||||
|
/// </summary>
|
||||||
|
public virtual IMongoCollection<TRole> RolesCollection => Context.GetCollection<TRole, TKey>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
/// Gets or sets the <see cref="IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -170,8 +180,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
var oldStamp = role.ConcurrencyStamp;
|
var oldStamp = role.ConcurrencyStamp;
|
||||||
role.ConcurrencyStamp = Guid.NewGuid().ToString();
|
role.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||||
var collection = MongoRepository.Context.GetCollection<TRole>();
|
var updateRes = await RolesCollection.ReplaceOneAsync(x => x.Id.Equals(role.Id)
|
||||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(role.Id)
|
|
||||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||||
role);
|
role);
|
||||||
if (updateRes.ModifiedCount == 0)
|
if (updateRes.ModifiedCount == 0)
|
||||||
@@ -197,8 +206,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
var oldStamp = role.ConcurrencyStamp;
|
var oldStamp = role.ConcurrencyStamp;
|
||||||
role.ConcurrencyStamp = Guid.NewGuid().ToString();
|
role.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||||
var collection = MongoRepository.Context.GetCollection<TRole>();
|
var deleteRes = await RolesCollection.DeleteOneAsync(x => x.Id.Equals(role.Id)
|
||||||
var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(role.Id)
|
|
||||||
&& x.ConcurrencyStamp.Equals(oldStamp));
|
&& x.ConcurrencyStamp.Equals(oldStamp));
|
||||||
if (deleteRes.DeletedCount == 0)
|
if (deleteRes.DeletedCount == 0)
|
||||||
{
|
{
|
||||||
@@ -272,11 +280,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||||
public virtual TKey ConvertIdFromString(string id)
|
public virtual TKey ConvertIdFromString(string id)
|
||||||
{
|
{
|
||||||
if (id == null)
|
return id.ToTKey<TKey>();
|
||||||
{
|
|
||||||
return default(TKey);
|
|
||||||
}
|
|
||||||
return (TKey)TypeDescriptor.GetConverter(typeof(TKey)).ConvertFromInvariantString(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -448,10 +452,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A navigation property for the roles the store contains.
|
|
||||||
/// </summary>
|
|
||||||
public virtual IQueryable<TRole> Roles => Context.GetCollection<TRole>().AsQueryable();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a entity representing a role claim.
|
/// Creates a entity representing a role claim.
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMongoCollection<TUser> UsersSet { get { return Context.GetCollection<TUser>(); } }
|
private IMongoCollection<TUser> UsersCollection { get { return Context.GetCollection<TUser, TKey>(); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called.
|
/// 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));
|
throw new ArgumentNullException(nameof(user));
|
||||||
}
|
}
|
||||||
await UsersSet.InsertOneAsync(user);
|
await UsersCollection.InsertOneAsync(user);
|
||||||
await SaveChanges(cancellationToken);
|
await SaveChanges(cancellationToken);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
@@ -171,8 +171,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
var oldStamp = user.ConcurrencyStamp;
|
var oldStamp = user.ConcurrencyStamp;
|
||||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
var updateRes = await UsersCollection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
||||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
|
||||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||||
user);
|
user);
|
||||||
if(updateRes.ModifiedCount == 0)
|
if(updateRes.ModifiedCount == 0)
|
||||||
@@ -202,8 +201,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
user.Tokens.Clear();
|
user.Tokens.Clear();
|
||||||
var oldStamp = user.ConcurrencyStamp;
|
var oldStamp = user.ConcurrencyStamp;
|
||||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
var deleteRes = await UsersCollection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
||||||
var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
|
||||||
&& x.ConcurrencyStamp.Equals(oldStamp));
|
&& x.ConcurrencyStamp.Equals(oldStamp));
|
||||||
if (deleteRes.DeletedCount == 0)
|
if (deleteRes.DeletedCount == 0)
|
||||||
{
|
{
|
||||||
@@ -248,7 +246,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override IQueryable<TUser> Users
|
public override IQueryable<TUser> Users
|
||||||
{
|
{
|
||||||
get { return UsersSet.AsQueryable(); }
|
get { return UsersCollection.AsQueryable(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -539,8 +537,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
var filter = Builders<TUser>.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value)
|
var filter = Builders<TUser>.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value)
|
||||||
&& userClaims.Type.Equals(claim.Type));
|
&& userClaims.Type.Equals(claim.Type));
|
||||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
var cursor = UsersCollection.Find(filter);
|
||||||
var cursor = collection.Find(filter);
|
|
||||||
var res = await cursor.ToListAsync();
|
var res = await cursor.ToListAsync();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-9
@@ -14,6 +14,8 @@ using AspNetCore.Identity.MongoDbCore.Extensions;
|
|||||||
using AspNetCore.Identity.MongoDbCore.Models;
|
using AspNetCore.Identity.MongoDbCore.Models;
|
||||||
using AspNetCore.Identity.MongoDbCore.Infrastructure;
|
using AspNetCore.Identity.MongoDbCore.Infrastructure;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using MongoDB.Bson;
|
||||||
|
|
||||||
namespace AspNetCore.Identity.MongoDbCore
|
namespace AspNetCore.Identity.MongoDbCore
|
||||||
{
|
{
|
||||||
@@ -130,21 +132,29 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static TContext Context { get; set; }
|
private static TContext Context { get; set; }
|
||||||
|
|
||||||
|
private static object MongoRepositoryInitializationLock = new object();
|
||||||
private static IMongoRepository _mongoRepository;
|
private static IMongoRepository _mongoRepository;
|
||||||
private static IMongoRepository MongoRepository
|
private static IMongoRepository MongoRepository
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
{
|
||||||
|
// double checked locking to prevent race to initialize the repository in multithreaded environment.
|
||||||
|
if (_mongoRepository == null)
|
||||||
|
{
|
||||||
|
lock (MongoRepositoryInitializationLock)
|
||||||
{
|
{
|
||||||
if (_mongoRepository == null)
|
if (_mongoRepository == null)
|
||||||
{
|
{
|
||||||
_mongoRepository = new MongoRepository(Context);
|
_mongoRepository = new MongoRepository(Context);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return _mongoRepository;
|
return _mongoRepository;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IMongoCollection<TUser> UsersSet { get { return Context.GetCollection<TUser>(); } }
|
private IMongoCollection<TUser> UsersCollection { get { return Context.GetCollection<TUser, TKey>(); } }
|
||||||
private IMongoCollection<TRole> Roles { get { return Context.GetCollection<TRole>(); } }
|
private IMongoCollection<TRole> RolesCollection { get { return Context.GetCollection<TRole, TKey>(); } }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a flag indicating if changes should be persisted after CreateAsync, UpdateAsync and DeleteAsync are called.
|
/// 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));
|
throw new ArgumentNullException(nameof(user));
|
||||||
}
|
}
|
||||||
await UsersSet.InsertOneAsync(user);
|
await UsersCollection.InsertOneAsync(user);
|
||||||
await SaveChanges(cancellationToken);
|
await SaveChanges(cancellationToken);
|
||||||
return IdentityResult.Success;
|
return IdentityResult.Success;
|
||||||
}
|
}
|
||||||
@@ -197,7 +207,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
var oldStamp = user.ConcurrencyStamp;
|
var oldStamp = user.ConcurrencyStamp;
|
||||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
var collection = MongoRepository.Context.GetCollection<TUser, TKey>();
|
||||||
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
var updateRes = await collection.ReplaceOneAsync(x => x.Id.Equals(user.Id)
|
||||||
&& x.ConcurrencyStamp.Equals(oldStamp),
|
&& x.ConcurrencyStamp.Equals(oldStamp),
|
||||||
user);
|
user);
|
||||||
@@ -228,8 +238,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
user.Tokens.Clear();
|
user.Tokens.Clear();
|
||||||
var oldStamp = user.ConcurrencyStamp;
|
var oldStamp = user.ConcurrencyStamp;
|
||||||
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
user.ConcurrencyStamp = Guid.NewGuid().ToString();
|
||||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
var deleteRes = await UsersCollection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
||||||
var deleteRes = await collection.DeleteOneAsync(x => x.Id.Equals(user.Id)
|
|
||||||
&& x.ConcurrencyStamp.Equals(oldStamp));
|
&& x.ConcurrencyStamp.Equals(oldStamp));
|
||||||
if (deleteRes.DeletedCount == 0)
|
if (deleteRes.DeletedCount == 0)
|
||||||
{
|
{
|
||||||
@@ -254,6 +263,16 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
return MongoRepository.GetByIdAsync<TUser, TKey>(id);
|
return MongoRepository.GetByIdAsync<TUser, TKey>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">The id to convert.</param>
|
||||||
|
/// <returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||||
|
public override TKey ConvertIdFromString(string id)
|
||||||
|
{
|
||||||
|
return id.ToTKey<TKey>();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds and returns a user, if any, who has the specified normalized user name.
|
/// Finds and returns a user, if any, who has the specified normalized user name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -274,7 +293,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public override IQueryable<TUser> Users
|
public override IQueryable<TUser> Users
|
||||||
{
|
{
|
||||||
get { return UsersSet.AsQueryable(); }
|
get { return UsersCollection.AsQueryable(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -711,8 +730,7 @@ namespace AspNetCore.Identity.MongoDbCore
|
|||||||
}
|
}
|
||||||
var filter = Builders<TUser>.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value)
|
var filter = Builders<TUser>.Filter.ElemMatch(x => x.Claims, userClaims => userClaims.Value.Equals(claim.Value)
|
||||||
&& userClaims.Type.Equals(claim.Type));
|
&& userClaims.Type.Equals(claim.Type));
|
||||||
var collection = MongoRepository.Context.GetCollection<TUser>();
|
var cursor = UsersCollection.Find(filter);
|
||||||
var cursor = collection.Find(filter);
|
|
||||||
var res = await cursor.ToListAsync();
|
var res = await cursor.ToListAsync();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"runtimeTarget": {
|
"runtimeTarget": {
|
||||||
"name": ".NETCoreApp,Version=v2.0",
|
"name": ".NETCoreApp,Version=v2.0",
|
||||||
"signature": "38e5f0ca5f25fc12f74d4c5d8051381123909848"
|
"signature": "38b2f87cafd1a2fa8c7bd3268841c3cd7abe472b"
|
||||||
},
|
},
|
||||||
"compilationOptions": {},
|
"compilationOptions": {},
|
||||||
"targets": {
|
"targets": {
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"Microsoft.AspNetCore.Identity": "2.0.1",
|
"Microsoft.AspNetCore.Identity": "2.0.1",
|
||||||
"Microsoft.Extensions.Identity.Stores": "2.0.1",
|
"Microsoft.Extensions.Identity.Stores": "2.0.1",
|
||||||
"MongoDB.Driver": "2.5.0",
|
"MongoDB.Driver": "2.5.0",
|
||||||
"MongoDbGenericRepository": "1.3.4"
|
"MongoDbGenericRepository": "1.3.6"
|
||||||
},
|
},
|
||||||
"runtime": {
|
"runtime": {
|
||||||
"AspNetCore.Identity.MongoDbCore.dll": {}
|
"AspNetCore.Identity.MongoDbCore.dll": {}
|
||||||
@@ -359,7 +359,7 @@
|
|||||||
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {}
|
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"MongoDbGenericRepository/1.3.4": {
|
"MongoDbGenericRepository/1.3.6": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"MongoDB.Driver": "2.5.0"
|
"MongoDB.Driver": "2.5.0"
|
||||||
},
|
},
|
||||||
@@ -1462,12 +1462,12 @@
|
|||||||
"path": "mongodb.driver.core/2.5.0",
|
"path": "mongodb.driver.core/2.5.0",
|
||||||
"hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
|
"hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
|
||||||
},
|
},
|
||||||
"MongoDbGenericRepository/1.3.4": {
|
"MongoDbGenericRepository/1.3.6": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"serviceable": true,
|
"serviceable": true,
|
||||||
"sha512": "sha512-nVtq9UGq6e8I61D1Fc1HIvh4qVA92IkfpcmrNXgG2141qBOpY7U0FbKlz+NOqiJoopY/ejhTBE3QbicsxsoOeg==",
|
"sha512": "sha512-bm4Q5RDLqt6rRZJTDiWvQpHOJ3ACxfELqg0kiZO8dyb7xMEqPQC7urpuLKMpDUmnE/pMBuXe6Pmy9TyTksDbdg==",
|
||||||
"path": "mongodbgenericrepository/1.3.4",
|
"path": "mongodbgenericrepository/1.3.6",
|
||||||
"hashPath": "mongodbgenericrepository.1.3.4.nupkg.sha512"
|
"hashPath": "mongodbgenericrepository.1.3.6.nupkg.sha512"
|
||||||
},
|
},
|
||||||
"runtime.native.System/4.3.0": {
|
"runtime.native.System/4.3.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
|
|||||||
Binary file not shown.
@@ -130,6 +130,19 @@
|
|||||||
<param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
<param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||||
<param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
<param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions">
|
||||||
|
<summary>
|
||||||
|
A set of extensions for string.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions.ToTKey``1(System.String)">
|
||||||
|
<summary>
|
||||||
|
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||||
|
</summary>
|
||||||
|
<typeparam name="TKey"></typeparam>
|
||||||
|
<param name="id"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:AspNetCore.Identity.MongoDbCore.GlobalVariables">
|
<member name="T:AspNetCore.Identity.MongoDbCore.GlobalVariables">
|
||||||
<summary>
|
<summary>
|
||||||
A class holding global variables.
|
A class holding global variables.
|
||||||
@@ -308,6 +321,11 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<param name="roleName">The name of the role.</param>
|
<param name="roleName">The name of the role.</param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.InitializeFields">
|
||||||
|
<summary>
|
||||||
|
Initialize the field of the MongoIdentityRole
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.#ctor(System.String,`0)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.#ctor(System.String,`0)">
|
||||||
<summary>
|
<summary>
|
||||||
The constructor for a <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1"/>, taking a role name and a primary key value.
|
The constructor for a <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1"/>, taking a role name and a primary key value.
|
||||||
@@ -425,6 +443,11 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<param name="userName">The name of the user.</param>
|
<param name="userName">The name of the user.</param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.InitializeFields">
|
||||||
|
<summary>
|
||||||
|
Initialize the field of the MongoIdentityUser
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.SetVersion(System.Int32)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.SetVersion(System.Int32)">
|
||||||
<summary>
|
<summary>
|
||||||
Sets the version of the schema for the <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1"/> document.
|
Sets the version of the schema for the <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1"/> document.
|
||||||
@@ -597,6 +620,16 @@
|
|||||||
Gets the database context for this store.
|
Gets the database context for this store.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
||||||
|
<summary>
|
||||||
|
A navigation property for the roles the store contains.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.RolesCollection">
|
||||||
|
<summary>
|
||||||
|
A navigation property for the roles the store contains.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.ErrorDescriber">
|
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.ErrorDescriber">
|
||||||
<summary>
|
<summary>
|
||||||
Gets or sets the <see cref="T:Microsoft.AspNetCore.Identity.IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
Gets or sets the <see cref="T:Microsoft.AspNetCore.Identity.IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
||||||
@@ -742,11 +775,6 @@
|
|||||||
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||||
<returns>The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
|
<returns>The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
|
||||||
<summary>
|
|
||||||
A navigation property for the roles the store contains.
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.CreateRoleClaim(`0,System.Security.Claims.Claim)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.CreateRoleClaim(`0,System.Security.Claims.Claim)">
|
||||||
<summary>
|
<summary>
|
||||||
Creates a entity representing a role claim.
|
Creates a entity representing a role claim.
|
||||||
@@ -1360,6 +1388,13 @@
|
|||||||
The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
|
The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
|
||||||
</returns>
|
</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.ConvertIdFromString(System.String)">
|
||||||
|
<summary>
|
||||||
|
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||||
|
</summary>
|
||||||
|
<param name="id">The id to convert.</param>
|
||||||
|
<returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||||
|
</member>
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.FindByNameAsync(System.String,System.Threading.CancellationToken)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.FindByNameAsync(System.String,System.Threading.CancellationToken)">
|
||||||
<summary>
|
<summary>
|
||||||
Finds and returns a user, if any, who has the specified normalized user name.
|
Finds and returns a user, if any, who has the specified normalized user name.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"runtimeTarget": {
|
"runtimeTarget": {
|
||||||
"name": ".NETStandard,Version=v2.0/",
|
"name": ".NETStandard,Version=v2.0/",
|
||||||
"signature": "9926fc91f43fdc960144838c1bcb58195d97fdd2"
|
"signature": "777efc9083cc946975cf0e3ebd09810483543683"
|
||||||
},
|
},
|
||||||
"compilationOptions": {},
|
"compilationOptions": {},
|
||||||
"targets": {
|
"targets": {
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"Microsoft.AspNetCore.Identity": "2.0.1",
|
"Microsoft.AspNetCore.Identity": "2.0.1",
|
||||||
"Microsoft.Extensions.Identity.Stores": "2.0.1",
|
"Microsoft.Extensions.Identity.Stores": "2.0.1",
|
||||||
"MongoDB.Driver": "2.5.0",
|
"MongoDB.Driver": "2.5.0",
|
||||||
"MongoDbGenericRepository": "1.3.4",
|
"MongoDbGenericRepository": "1.3.6",
|
||||||
"NETStandard.Library": "2.0.1"
|
"NETStandard.Library": "2.0.1"
|
||||||
},
|
},
|
||||||
"runtime": {
|
"runtime": {
|
||||||
@@ -360,7 +360,7 @@
|
|||||||
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {}
|
"lib/netstandard1.5/MongoDB.Driver.Core.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"MongoDbGenericRepository/1.3.4": {
|
"MongoDbGenericRepository/1.3.6": {
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"MongoDB.Driver": "2.5.0"
|
"MongoDB.Driver": "2.5.0"
|
||||||
},
|
},
|
||||||
@@ -1427,12 +1427,12 @@
|
|||||||
"path": "mongodb.driver.core/2.5.0",
|
"path": "mongodb.driver.core/2.5.0",
|
||||||
"hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
|
"hashPath": "mongodb.driver.core.2.5.0.nupkg.sha512"
|
||||||
},
|
},
|
||||||
"MongoDbGenericRepository/1.3.4": {
|
"MongoDbGenericRepository/1.3.6": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"serviceable": true,
|
"serviceable": true,
|
||||||
"sha512": "sha512-nVtq9UGq6e8I61D1Fc1HIvh4qVA92IkfpcmrNXgG2141qBOpY7U0FbKlz+NOqiJoopY/ejhTBE3QbicsxsoOeg==",
|
"sha512": "sha512-bm4Q5RDLqt6rRZJTDiWvQpHOJ3ACxfELqg0kiZO8dyb7xMEqPQC7urpuLKMpDUmnE/pMBuXe6Pmy9TyTksDbdg==",
|
||||||
"path": "mongodbgenericrepository/1.3.4",
|
"path": "mongodbgenericrepository/1.3.6",
|
||||||
"hashPath": "mongodbgenericrepository.1.3.4.nupkg.sha512"
|
"hashPath": "mongodbgenericrepository.1.3.6.nupkg.sha512"
|
||||||
},
|
},
|
||||||
"NETStandard.Library/2.0.1": {
|
"NETStandard.Library/2.0.1": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
|
|||||||
Binary file not shown.
@@ -130,6 +130,19 @@
|
|||||||
<param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
<param name="mongoDbIdentityConfiguration">A configuration object of the AspNetCore.Identity.MongoDbCore package.</param>
|
||||||
<param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
<param name="mongoDbContext">An object representing a MongoDb connection.</param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="T:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions">
|
||||||
|
<summary>
|
||||||
|
A set of extensions for string.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.Extensions.StringExtensions.ToTKey``1(System.String)">
|
||||||
|
<summary>
|
||||||
|
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||||
|
</summary>
|
||||||
|
<typeparam name="TKey"></typeparam>
|
||||||
|
<param name="id"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="T:AspNetCore.Identity.MongoDbCore.GlobalVariables">
|
<member name="T:AspNetCore.Identity.MongoDbCore.GlobalVariables">
|
||||||
<summary>
|
<summary>
|
||||||
A class holding global variables.
|
A class holding global variables.
|
||||||
@@ -308,6 +321,11 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<param name="roleName">The name of the role.</param>
|
<param name="roleName">The name of the role.</param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.InitializeFields">
|
||||||
|
<summary>
|
||||||
|
Initialize the field of the MongoIdentityRole
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.#ctor(System.String,`0)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1.#ctor(System.String,`0)">
|
||||||
<summary>
|
<summary>
|
||||||
The constructor for a <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1"/>, taking a role name and a primary key value.
|
The constructor for a <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityRole`1"/>, taking a role name and a primary key value.
|
||||||
@@ -425,6 +443,11 @@
|
|||||||
</summary>
|
</summary>
|
||||||
<param name="userName">The name of the user.</param>
|
<param name="userName">The name of the user.</param>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.InitializeFields">
|
||||||
|
<summary>
|
||||||
|
Initialize the field of the MongoIdentityUser
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.SetVersion(System.Int32)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1.SetVersion(System.Int32)">
|
||||||
<summary>
|
<summary>
|
||||||
Sets the version of the schema for the <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1"/> document.
|
Sets the version of the schema for the <see cref="T:AspNetCore.Identity.MongoDbCore.Models.MongoIdentityUser`1"/> document.
|
||||||
@@ -597,6 +620,16 @@
|
|||||||
Gets the database context for this store.
|
Gets the database context for this store.
|
||||||
</summary>
|
</summary>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
||||||
|
<summary>
|
||||||
|
A navigation property for the roles the store contains.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
|
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.RolesCollection">
|
||||||
|
<summary>
|
||||||
|
A navigation property for the roles the store contains.
|
||||||
|
</summary>
|
||||||
|
</member>
|
||||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.ErrorDescriber">
|
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.ErrorDescriber">
|
||||||
<summary>
|
<summary>
|
||||||
Gets or sets the <see cref="T:Microsoft.AspNetCore.Identity.IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
Gets or sets the <see cref="T:Microsoft.AspNetCore.Identity.IdentityErrorDescriber"/> for any error that occurred with the current operation.
|
||||||
@@ -742,11 +775,6 @@
|
|||||||
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
<param name="cancellationToken">The <see cref="T:System.Threading.CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
|
||||||
<returns>The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
|
<returns>The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation.</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="P:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.Roles">
|
|
||||||
<summary>
|
|
||||||
A navigation property for the roles the store contains.
|
|
||||||
</summary>
|
|
||||||
</member>
|
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.CreateRoleClaim(`0,System.Security.Claims.Claim)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.MongoRoleStore`5.CreateRoleClaim(`0,System.Security.Claims.Claim)">
|
||||||
<summary>
|
<summary>
|
||||||
Creates a entity representing a role claim.
|
Creates a entity representing a role claim.
|
||||||
@@ -1360,6 +1388,13 @@
|
|||||||
The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
|
The <see cref="T:System.Threading.Tasks.Task"/> that represents the asynchronous operation, containing the user matching the specified <paramref name="userId"/> if it exists.
|
||||||
</returns>
|
</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.ConvertIdFromString(System.String)">
|
||||||
|
<summary>
|
||||||
|
Converts the provided <paramref name="id"/> to a strongly typed key object.
|
||||||
|
</summary>
|
||||||
|
<param name="id">The id to convert.</param>
|
||||||
|
<returns>An instance of <typeparamref name="TKey"/> representing the provided <paramref name="id"/>.</returns>
|
||||||
|
</member>
|
||||||
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.FindByNameAsync(System.String,System.Threading.CancellationToken)">
|
<member name="M:AspNetCore.Identity.MongoDbCore.MongoUserStore`9.FindByNameAsync(System.String,System.Threading.CancellationToken)">
|
||||||
<summary>
|
<summary>
|
||||||
Finds and returns a user, if any, who has the specified normalized user name.
|
Finds and returns a user, if any, who has the specified normalized user name.
|
||||||
|
|||||||
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.7" />
|
<PackageReference Include="AspNetCore.Identity.MongoDbCore" Version="1.0.8" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Http" />
|
<PackageReference Include="Microsoft.AspNetCore.Http" />
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.1" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
|
||||||
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
<PackageReference Include="MongoDB.Driver" Version="2.5.0" />
|
||||||
<PackageReference Include="MongoDbGenericRepository" Version="1.3.4" />
|
<PackageReference Include="MongoDbGenericRepository" Version="1.3.6" />
|
||||||
<PackageReference Include="Moq" Version="4.8.1" />
|
<PackageReference Include="Moq" Version="4.8.1" />
|
||||||
<PackageReference Include="xunit" Version="2.3.1" />
|
<PackageReference Include="xunit" Version="2.3.1" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
|
||||||
|
|||||||
+1
-1
@@ -162,7 +162,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
|||||||
|
|
||||||
private IQueryable<TUser> GetQueryable()
|
private IQueryable<TUser> GetQueryable()
|
||||||
{
|
{
|
||||||
return Container.MongoRepository.Context.GetCollection<TUser>().AsQueryable();
|
return Container.MongoRepository.Context.GetCollection<TUser, TKey>().AsQueryable();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
+1
-1
@@ -87,7 +87,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
|||||||
|
|
||||||
private IQueryable<TUser> GetQueryable()
|
private IQueryable<TUser> GetQueryable()
|
||||||
{
|
{
|
||||||
return Container.MongoRepository.Context.GetCollection<TUser>().AsQueryable();
|
return Container.MongoRepository.Context.GetCollection<TUser, TKey>().AsQueryable();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
+56
@@ -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<ObjectId>
|
||||||
|
{
|
||||||
|
public ObjectIdUser() : base()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ObjectIdRole : MongoIdentityRole<ObjectId>
|
||||||
|
{
|
||||||
|
public ObjectIdRole() : base()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class UserStoreObjectIdTest : MongoDbStoreTestBase<ObjectIdUser, ObjectIdRole, ObjectId>
|
||||||
|
{
|
||||||
|
public UserStoreObjectIdTest(MongoDatabaseFixture<ObjectIdUser, ObjectIdRole, ObjectId> fixture)
|
||||||
|
: base(fixture)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApplicationUserStore : MongoUserStore<ObjectIdUser, ObjectIdRole, IMongoDbContext, ObjectId>
|
||||||
|
{
|
||||||
|
public ApplicationUserStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ApplicationRoleStore : MongoRoleStore<ObjectIdRole, IMongoDbContext, ObjectId>
|
||||||
|
{
|
||||||
|
public ApplicationRoleStore(IMongoDbContext context) : base(Container.MongoRepository.Context) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AddUserStore(IServiceCollection services, object context = null)
|
||||||
|
{
|
||||||
|
services.AddSingleton<IUserStore<ObjectIdUser>>(new ApplicationUserStore(Container.MongoRepository.Context));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void AddRoleStore(IServiceCollection services, object context = null)
|
||||||
|
{
|
||||||
|
services.AddSingleton<IRoleStore<ObjectIdRole>>(new ApplicationRoleStore(Container.MongoRepository.Context));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -31,7 +31,7 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
|||||||
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
||||||
if (userIds.Any())
|
if (userIds.Any())
|
||||||
{
|
{
|
||||||
Context.GetCollection<TUser>().DeleteMany(e => userIds.Contains(e.Id));
|
Context.GetCollection<TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,12 +57,12 @@ namespace AspNetCore.Identity.MongoDbCore.Test
|
|||||||
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
var userIds = UsersToDelete.ToList().Select(e => e.Id);
|
||||||
if (userIds.Any())
|
if (userIds.Any())
|
||||||
{
|
{
|
||||||
Context.GetCollection<TUser>().DeleteMany(e => userIds.Contains(e.Id));
|
Context.GetCollection<TUser, TKey>().DeleteMany(e => userIds.Contains(e.Id));
|
||||||
}
|
}
|
||||||
var roleIds = RolesToDelete.ToList().Select(e => e.Id);
|
var roleIds = RolesToDelete.ToList().Select(e => e.Id);
|
||||||
if (roleIds.Any())
|
if (roleIds.Any())
|
||||||
{
|
{
|
||||||
Context.GetCollection<TRole>().DeleteMany(e => roleIds.Contains(e.Id));
|
Context.GetCollection<TRole, TKey>().DeleteMany(e => roleIds.Contains(e.Id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user