Skip to content

Commit

Permalink
Remove obsolete properties (matteofabbri#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddesmet committed Oct 25, 2021
1 parent f91b2f9 commit a76c070
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/AspNetCore.Identity.Mongo/Migrations/Migrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class Migrator

public static void Apply<TUser, TRole, TKey>(IMongoCollection<MigrationHistory> migrationCollection, IMongoCollection<TUser> usersCollection, IMongoCollection<TRole> rolesCollection)
where TKey : IEquatable<TKey>
where TUser : MongoUser<TKey>
where TUser : MigrationMongoUser<TKey>
where TRole : MongoRole<TKey>
{
var history = migrationCollection.Find(_ => true).ToList();
Expand Down
40 changes: 40 additions & 0 deletions src/AspNetCore.Identity.Mongo/Model/MigrationMongoUser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using DnsClient;
using System.Data;
using System.Security.Claims;
using Microsoft.AspNetCore.Identity;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace AspNetCore.Identity.Mongo.Model
{
internal class MigrationMongoUser : MigrationMongoUser<ObjectId>
{
public MigrationMongoUser() : base() { }
}

internal class MigrationMongoUser<TKey> : IdentityUser<TKey> where TKey : IEquatable<TKey>
{
public MigrationMongoUser()
{
Roles = new List<string>();
Claims = new List<IdentityUserClaim<string>>();
Logins = new List<IdentityUserLogin<string>>();
Tokens = new List<IdentityUserToken<string>>();
RecoveryCodes = new List<TwoFactorRecoveryCode>();
}

public string AuthenticatorKey { get; set; }

public List<string> Roles { get; set; }

public List<IdentityUserClaim<string>> Claims { get; set; }

public List<IdentityUserLogin<string>> Logins { get; set; }

public List<IdentityUserToken<string>> Tokens { get; set; }

public List<TwoFactorRecoveryCode> RecoveryCodes { get; set; }
}
}
6 changes: 3 additions & 3 deletions src/AspNetCore.Identity.Mongo/Model/MongoRole.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.AspNetCore.Identity;
using MongoDB.Bson;
using System;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using MongoDB.Bson;

namespace AspNetCore.Identity.Mongo.Model
{
Expand Down
8 changes: 0 additions & 8 deletions src/AspNetCore.Identity.Mongo/Model/MongoUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,12 @@ public MongoUser(string userName) : this()
NormalizedUserName = userName.ToUpperInvariant();
}

[BsonIgnore]
[Obsolete("This property moved to Tokens and should not be used anymore! Will be removed in future versions.")]
public string AuthenticatorKey { get; set; }

public List<string> Roles { get; set; }

public List<IdentityUserClaim<string>> Claims { get; set; }

public List<IdentityUserLogin<string>> Logins { get; set; }

public List<IdentityUserToken<string>> Tokens { get; set; }

[BsonIgnore]
[Obsolete("This property moved to Tokens and should not be used anymore! Will be removed in future versions.")]
public List<TwoFactorRecoveryCode> RecoveryCodes { get; set; }
}
}
3 changes: 1 addition & 2 deletions src/AspNetCore.Identity.Mongo/Model/TwoFactorRecoveryCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

namespace AspNetCore.Identity.Mongo.Model
{
[Obsolete("This property moved to Tokens and should not be used anymore! Will be removed in future versions.")]
public class TwoFactorRecoveryCode
internal class TwoFactorRecoveryCode
{
public string Code { get; set; }

Expand Down
3 changes: 2 additions & 1 deletion src/AspNetCore.Identity.Mongo/MongoIdentityExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ public static IdentityBuilder AddIdentityMongoDbProvider<TUser>(this IServiceCol
setupDatabaseAction(dbOptions);

var migrationCollection = MongoUtil.FromConnectionString<MigrationHistory>(dbOptions, dbOptions.MigrationCollection);
var migrationUserCollection = MongoUtil.FromConnectionString<MigrationMongoUser<TKey>>(dbOptions, dbOptions.UsersCollection);
var userCollection = MongoUtil.FromConnectionString<TUser>(dbOptions, dbOptions.UsersCollection);
var roleCollection = MongoUtil.FromConnectionString<TRole>(dbOptions, dbOptions.RolesCollection);

// apply migrations before identity services resolved
Migrator.Apply<TUser, TRole, TKey>(migrationCollection, userCollection, roleCollection);
Migrator.Apply<MigrationMongoUser<TKey>, TRole, TKey>(migrationCollection, migrationUserCollection, roleCollection);

var builder = services.AddIdentity<TUser, TRole>(setupIdentityAction ?? (x => { }));

Expand Down
15 changes: 8 additions & 7 deletions src/AspNetCore.Identity.Mongo/MongoStoreExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using AspNetCore.Identity.Mongo.Migrations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Threading.Tasks;
using AspNetCore.Identity.Mongo.Migrations;
using AspNetCore.Identity.Mongo.Model;
using AspNetCore.Identity.Mongo.Mongo;
using AspNetCore.Identity.Mongo.Stores;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Threading.Tasks;

namespace AspNetCore.Identity.Mongo
{
Expand All @@ -32,10 +32,11 @@ public static class MongoStoreExtensions
setupDatabaseAction(dbOptions);

var migrationCollection = MongoUtil.FromConnectionString<MigrationHistory>(dbOptions, dbOptions.MigrationCollection);
var migrationUserCollection = MongoUtil.FromConnectionString<MigrationMongoUser<TKey>>(dbOptions, dbOptions.UsersCollection);
var userCollection = MongoUtil.FromConnectionString<TUser>(dbOptions, dbOptions.UsersCollection);
var roleCollection = MongoUtil.FromConnectionString<TRole>(dbOptions, dbOptions.RolesCollection);

Migrator.Apply<TUser, TRole, TKey>(migrationCollection, userCollection, roleCollection);
Migrator.Apply<MigrationMongoUser<TKey>, TRole, TKey>(migrationCollection, migrationUserCollection, roleCollection);

builder.Services.AddSingleton(x => userCollection);
builder.Services.AddSingleton(x => roleCollection);
Expand Down

0 comments on commit a76c070

Please sign in to comment.