Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions IdentityRole.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace MongoDB.AspNet.Identity
{
/// <summary>
/// Represents a role in the identity system.
/// </summary>
public class IdentityRole
{
/// <summary>
/// Gets or sets the unique identifier for this role.
/// </summary>
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public virtual string Id { get; set; } = ObjectId.GenerateNewId().ToString();

/// <summary>
/// Gets or sets the name for this role.
/// </summary>
public virtual string? Name { get; set; }

/// <summary>
/// Gets or sets the normalized name for this role.
/// </summary>
public virtual string? NormalizedName { get; set; }

/// <summary>
/// Gets or sets a random value that should change when the role is persisted to the store.
/// </summary>
public virtual string? ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString();

/// <summary>
/// Initializes a new instance of the <see cref="IdentityRole"/> class.
/// </summary>
public IdentityRole()
{
}

/// <summary>
/// Initializes a new instance of the <see cref="IdentityRole"/> class with the specified role name.
/// </summary>
/// <param name="roleName">The role name.</param>
public IdentityRole(string roleName) : this()
{
Name = roleName;
}
}
}
125 changes: 70 additions & 55 deletions IdentityUser.cs
Original file line number Diff line number Diff line change
@@ -1,109 +1,124 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;


namespace MongoDB.AspNet.Identity
{
/// <summary>
/// Class IdentityUser.
/// Represents a user in the identity system.
/// </summary>
public class IdentityUser : IUser<string>
public class IdentityUser
{
/// <summary>
/// Unique key for the user
/// Gets or sets the unique identifier for this user.
/// </summary>
/// <value>The identifier.</value>
/// <returns>The unique key for the user</returns>
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public virtual string Id { get; set; }
public virtual string Id { get; set; } = null!;

/// <summary>
/// Gets or sets the name of the user.
/// Gets or sets the user name for this user.
/// </summary>
/// <value>The name of the user.</value>
public virtual string UserName { get; set; }
public virtual string? UserName { get; set; }

/// <summary>
/// Gets or sets the password hash.
/// Gets or sets the normalized user name for this user.
/// </summary>
/// <value>The password hash.</value>
public virtual string PasswordHash { get; set; }
public virtual string? NormalizedUserName { get; set; }

/// <summary>
/// Gets or sets the security stamp.
/// Gets or sets the email address for this user.
/// </summary>
/// <value>The security stamp.</value>
public virtual string SecurityStamp { get; set; }
public virtual string? Email { get; set; }

/// <summary>
/// Gets the roles.
/// Gets or sets the normalized email address for this user.
/// </summary>
/// <value>The roles.</value>
public virtual List<string> Roles { get; private set; }
public virtual string? NormalizedEmail { get; set; }

/// <summary>
/// Gets the claims.
/// Gets or sets a flag indicating if the email address has been confirmed.
/// </summary>
/// <value>The claims.</value>
public virtual List<IdentityUserClaim> Claims { get; private set; }
public virtual bool EmailConfirmed { get; set; }

/// <summary>
/// Gets the logins.
/// Gets or sets the password hash for this user.
/// </summary>
/// <value>The logins.</value>
public virtual List<UserLoginInfo> Logins { get; private set; }
public virtual string? PasswordHash { get; set; }

/// <summary>
/// Gets the phone number
/// Gets or sets a random value that should change when a user's credentials change.
/// </summary>
public virtual string PhoneNumber { get; set; }
public virtual string? SecurityStamp { get; set; }

/// <summary>
/// Gets Email address
/// Gets or sets a random value that should change when a user is persisted to the store.
/// </summary>
public virtual string Email { get; set; }
public virtual string? ConcurrencyStamp { get; set; } = Guid.NewGuid().ToString();

/// <summary>
///
/// Gets or sets the phone number for this user.
/// </summary>
public virtual bool EmailConfirmed { get; set; }
public virtual string? PhoneNumber { get; set; }

/// <summary>
/// Gets or sets a flag indicating if the phone number has been confirmed.
/// </summary>
public virtual bool PhoneNumberConfirmed { get; set; }

/// <summary>
///
/// Gets or sets a flag indicating if two factor authentication is enabled for this user.
/// </summary>
public DateTime? LockoutEndDateUtc { get; set; } = DateTime.Now.ToUniversalTime();
public virtual bool TwoFactorEnabled { get; set; }

/// <summary>
///
/// Gets or sets the date and time when any user lockout ends.
/// </summary>
public int AccessFailedCount { get; set; }
public virtual DateTimeOffset? LockoutEnd { get; set; }

/// <summary>
///
/// Gets or sets a flag indicating if lockout is enabled for this user.
/// </summary>
public bool LockoutEnabled { get; set; }
public virtual bool LockoutEnabled { get; set; }

/// <summary>
///
/// Gets or sets the number of failed login attempts for this user.
/// </summary>
public bool TwoFactorEnabled { get; set; }
public virtual int AccessFailedCount { get; set; }

/// <summary>
/// Gets the roles for this user.
/// </summary>
public virtual List<string> Roles { get; private set; } = new List<string>();

/// <summary>
/// Gets the claims for this user.
/// </summary>
public virtual List<IdentityUserClaim> Claims { get; private set; } = new List<IdentityUserClaim>();

/// <summary>
/// Gets the logins for this user.
/// </summary>
public virtual List<IdentityUserLogin> Logins { get; private set; } = new List<IdentityUserLogin>();

/// <summary>
/// Gets the authentication tokens for this user.
/// </summary>
public virtual List<IdentityUserToken> Tokens { get; private set; } = new List<IdentityUserToken>();

/// <summary>
/// Initializes a new instance of the <see cref="IdentityUser"/> class.
/// </summary>
public IdentityUser()
{
this.Claims = new List<IdentityUserClaim>();
this.Roles = new List<string>();
this.Logins = new List<UserLoginInfo>();
}
{
}

/// <summary>
/// Initializes a new instance of the <see cref="IdentityUser"/> class.
/// Initializes a new instance of the <see cref="IdentityUser"/> class with the specified user name.
/// </summary>
/// <param name="userName">Name of the user.</param>
public IdentityUser(string userName) : this()
{
this.UserName = userName;
}
}
/// <param name="userName">The user name.</param>
public IdentityUser(string userName) : this()
{
UserName = userName;
}
}
}
42 changes: 23 additions & 19 deletions IdentityUserClaim.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using System.Security.Claims;

namespace MongoDB.AspNet.Identity
{
/// <summary>
/// Class IdentityUserClaim.
/// Represents a claim that a user possesses.
/// </summary>
public class IdentityUserClaim
{
/// <summary>
/// Gets or sets the identifier.
/// Gets or sets the claim type for this claim.
/// </summary>
/// <value>The identifier.</value>
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public virtual string Id { get; set; }
public virtual string ClaimType { get; set; } = null!;

/// <summary>
/// Gets or sets the user identifier.
/// Gets or sets the claim value for this claim.
/// </summary>
/// <value>The user identifier.</value>
public virtual string UserId { get; set; }
public virtual string? ClaimValue { get; set; }

/// <summary>
/// Gets or sets the type of the claim.
/// Converts the entity into a Claim instance.
/// </summary>
/// <value>The type of the claim.</value>
public virtual string ClaimType { get; set; }
/// <returns>A <see cref="Claim"/> representing the claim.</returns>
public virtual Claim ToClaim()
{
return new Claim(ClaimType, ClaimValue ?? string.Empty);
}

/// <summary>
/// Gets or sets the claim value.
/// Initializes this instance from the specified claim.
/// </summary>
/// <value>The claim value.</value>
public virtual string ClaimValue { get; set; }

/// <param name="claim">The claim to initialize from.</param>
public virtual void InitializeFromClaim(Claim claim)
{
ClaimType = claim.Type;
ClaimValue = claim.Value;
}
}
}
}
23 changes: 23 additions & 0 deletions IdentityUserLogin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace MongoDB.AspNet.Identity
{
/// <summary>
/// Represents a login and its associated provider for a user.
/// </summary>
public class IdentityUserLogin
{
/// <summary>
/// Gets or sets the login provider (e.g., google, facebook, twitter).
/// </summary>
public virtual string LoginProvider { get; set; } = null!;

/// <summary>
/// Gets or sets the unique identifier for this login provided by the login provider.
/// </summary>
public virtual string ProviderKey { get; set; } = null!;

/// <summary>
/// Gets or sets the friendly name used in a UI for this login.
/// </summary>
public virtual string? ProviderDisplayName { get; set; }
}
}
23 changes: 23 additions & 0 deletions IdentityUserToken.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace MongoDB.AspNet.Identity
{
/// <summary>
/// Represents an authentication token for a user.
/// </summary>
public class IdentityUserToken
{
/// <summary>
/// Gets or sets the login provider this token is from.
/// </summary>
public virtual string LoginProvider { get; set; } = null!;

/// <summary>
/// Gets or sets the name of the token.
/// </summary>
public virtual string Name { get; set; } = null!;

/// <summary>
/// Gets or sets the value of the token.
/// </summary>
public virtual string? Value { get; set; }
}
}
Loading