Diiwo.Identity 0.1.2

dotnet add package Diiwo.Identity --version 0.1.2
                    
NuGet\Install-Package Diiwo.Identity -Version 0.1.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Diiwo.Identity" Version="0.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Diiwo.Identity" Version="0.1.2" />
                    
Directory.Packages.props
<PackageReference Include="Diiwo.Identity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Diiwo.Identity --version 0.1.2
                    
#r "nuget: Diiwo.Identity, 0.1.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Diiwo.Identity@0.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Diiwo.Identity&version=0.1.2
                    
Install as a Cake Addin
#tool nuget:?package=Diiwo.Identity&version=0.1.2
                    
Install as a Cake Tool

๐ŸŽฏ DIIWO Identity Solution

Dual-architecture identity management library for modern .NET applications

CI - Build and Test License: MIT .NET NuGet GitHub

๐Ÿ—๏ธ Dual Architecture Design

This library provides two distinct architectures to choose from based on your project needs:

๐ŸŽช App Architecture - Simple & Standalone

Perfect for lightweight applications and microservices.

  • โœ… No ASP.NET Core Identity dependencies
  • โœ… Optimized database schema without Identity overhead
  • โœ… Full control over authentication and authorization
  • โœ… Ideal for: APIs, microservices, console applications
  • ๐Ÿ—ƒ๏ธ Entities: AppUser, AppRole, AppGroup, AppPermission

๐Ÿข AspNet Architecture - Enterprise Ready โœ…

Built on ASP.NET Core Identity with enterprise extensions.

  • โœ… Full ASP.NET Core Identity integration
  • โœ… Compatible with UserManager<T>, RoleManager<T>, SignInManager<T>
  • โœ… Enterprise features on top of standard Identity
  • โœ… Ideal for: Web applications, enterprise systems
  • ๐Ÿ—ƒ๏ธ Entities: IdentityUser, IdentityRole, IdentityGroup, IdentityPermission

โšก Current Implementation Status

โœ… Recently Completed Features

  • ๐Ÿ—๏ธ Dual Architecture Implementation

    • App Architecture: Complete standalone implementation (AppUser, AppRole, AppGroup, AppPermission)
    • AspNet Architecture: Full ASP.NET Core Identity integration (IdentityUser, IdentityRole, IdentityGroup, IdentityPermission)
    • Database contexts with seeding for both architectures
    • Service layers with complete business logic
  • ๐Ÿ” Enterprise Audit Trail System โญ NEW

    • Automatic audit tracking - CreatedAt, UpdatedAt, CreatedBy, UpdatedBy fields managed automatically
    • Soft delete support - Entities marked as Terminated instead of hard deletion
    • Entity state management - Track entity lifecycle with EntityState enum
    • Zero manual code - All audit trails handled by AuditInterceptor from Diiwo.Core
    • Compliance ready - Enterprise-grade audit capabilities for regulatory requirements
    • Complete examples - Comprehensive demonstrations in /examples directory
  • ๐Ÿš€ Enterprise Session Management โญ NEW

    • Advanced session tracking - Device fingerprinting, location tracking, SSO support
    • JWT refresh tokens - Secure token-based authentication with automatic refresh
    • Session security - IP tracking, user agent validation, concurrent session limits
    • Enterprise features - SSO provider integration, device management
    • Complete audit trail - All session activities automatically tracked
  • ๐Ÿš€ Advanced Permission System

    • 5-level permission hierarchy with priority-based evaluation
    • Automatic permission generation from entity attributes
    • Simplified workflow for direct database application
    • Traditional migration workflow for enterprise deployment
    • CLI commands for streamlined development
    • Full audit trail for all permission changes
  • ๐Ÿงช Comprehensive Test Suite

    • Entity tests for both architectures with detailed documentation
    • Integration tests for database operations and relationships
    • Service tests with complete business logic validation
    • CLI tests for permission generation workflows
    • All tests include detailed assert comments for clarity
  • ๐Ÿ“ฆ Modern Project Structure

    • Organized src/ and tests/ directory structure
    • Separate projects for App, AspNet, Shared, and Migration components
    • Solution file with proper project references
    • Integration with Diiwo.Core for base entities and automatic auditing
  • ๐Ÿ“– Comprehensive Documentation โœ…

    • Complete architecture comparison guide (App vs AspNet)
    • Enterprise implementation examples and patterns
    • Production deployment strategies and best practices
    • Migration guides for architecture transitions

๐Ÿšง Currently In Development

  • ๐Ÿ”„ Migration Services - Architecture conversion utilities
    • App โ†” AspNet migration services
    • Data migration between architectures
    • Validation and rollback capabilities

๐Ÿ“‹ Planned Features

  • ๐ŸŒ Multi-database support (PostgreSQL, SQLite, MySQL)
  • ๐Ÿ“ฆ NuGet package publishing and distribution
  • ๐Ÿ”ง Enhanced migration tools with validation and rollback
  • ๐ŸŽฏ Performance optimizations and caching strategies
  • ๐Ÿ”’ Advanced security features (MFA, risk-based authentication)
  • ๐Ÿ“Š Analytics dashboard for user behavior and security monitoring

๐Ÿ” Enterprise Audit Trail System

Zero-code automatic audit tracking powered by Diiwo.Core AuditInterceptor:

โœจ Key Features

  • ๐ŸŽฏ Automatic Tracking: CreatedAt, UpdatedAt, CreatedBy, UpdatedBy - no manual code required
  • ๐Ÿ—‘๏ธ Soft Delete: Entities marked as Terminated instead of permanent deletion
  • ๐Ÿ“Š State Management: Track entity lifecycle with EntityState enum (Active, Inactive, Terminated)
  • ๐Ÿ‘ค User Attribution: Automatic tracking of who made changes and when
  • ๐Ÿข Compliance Ready: Enterprise-grade audit capabilities for regulatory requirements

๐ŸŽช App Architecture Implementation

// App entities inherit from DomainEntity - automatic audit trail!
public class AppUser : DomainEntity  // โœ… Inherits all audit capabilities
{
    public required string Email { get; set; }
    public required string PasswordHash { get; set; }
    // CreatedAt, UpdatedAt, CreatedBy, UpdatedBy automatically managed!
}

๐Ÿข AspNet Architecture Implementation

// AspNet entities implement IDomainEntity - automatic audit trail!
public class IdentityUser : IdentityUser<Guid>, IDomainEntity  // โœ… Enterprise audit
{
    public string? FirstName { get; set; }
    // Audit fields (CreatedAt, UpdatedAt, etc.) automatically managed!
}

๐Ÿ“ Service Layer - No Manual Audit Code!

// Before: Manual audit assignments โŒ
var user = new AppUser
{
    Email = "user@example.com",
    CreatedAt = DateTime.UtcNow,        // โŒ Manual
    UpdatedAt = DateTime.UtcNow,        // โŒ Manual
    CreatedBy = currentUserId           // โŒ Manual
};

// After: Automatic audit tracking โœ…
var user = new AppUser
{
    Email = "user@example.com"
    // โœ… CreatedAt, UpdatedAt, CreatedBy, UpdatedBy set automatically!
};

๐ŸŽฏ 5-Level Permission System

Advanced permission hierarchy with priority-based evaluation:

1. ๐Ÿ† Role Permissions     (Priority 0 - HIGHEST)
2. ๐Ÿ‘ฅ Group Permissions    (Priority 50)
3. ๐Ÿ‘ค User Permissions     (Priority 100)
4. ๐Ÿ“Š Model Permissions    (Priority 150)
5. ๐ŸŽฏ Object Permissions   (Priority 200 - LOWEST)

Permission Evaluation Logic:

  • โŒ DENY always wins over GRANT
  • ๐Ÿ† Higher priority (lower number) takes precedence
  • ๐Ÿ”’ Deny by default if no explicit permissions exist
  • ๐Ÿ” Full audit trail for all permission changes

๐Ÿ”ง Dependencies

This project depends on:

  • Diiwo.Core - Base entities and shared functionality
  • .NET 8.0 - Latest .NET framework
  • Entity Framework Core - Data access and ORM

๐Ÿš€ Quick Start

Installation

# Clone the repository
git clone https://github.com/diiwo/diiwo-identity.git

# Navigate to project directory
cd diiwo-identity

# Restore dependencies (including Diiwo.Core)
dotnet restore

# Run tests to verify installation
dotnet test

Current App Architecture Usage (with Enterprise Audit)

// โœ… Enterprise-ready entity with automatic audit trail
var user = new AppUser
{
    Email = "user@example.com",
    PasswordHash = "hashed-password",
    FirstName = "John",
    LastName = "Doe"
    // โœ… CreatedAt, UpdatedAt, CreatedBy, UpdatedBy automatically set!
};

// Permission checking with audit trail
var hasPermission = await _permissionService.UserHasPermissionAsync(userId, "Documents", "Read");

// User management with automatic audit tracking
var newUser = await _userService.CreateUserAsync("user@example.com", hashedPassword, "John", "Doe");
// โœ… All changes automatically tracked with full audit trail!

// Soft delete - preserves audit history
await _userService.DeleteUserAsync(userId);
// โœ… User marked as 'Terminated', not permanently deleted

Enterprise AspNet Architecture Usage

// โœ… ASP.NET Core Identity + Enterprise audit trail
var identityUser = new IdentityUser
{
    Email = "enterprise@example.com",
    UserName = "enterprise-user",
    FirstName = "Enterprise",
    LastName = "User"
    // โœ… IDomainEntity interface provides automatic audit trail!
};

// Full ASP.NET Core Identity integration with audit
var result = await _userManager.CreateAsync(identityUser, "SecurePassword123!");
// โœ… All Identity operations tracked with enterprise audit trail!

// Advanced permission system with audit
await _permissionService.AssignPermissionToUserAsync(userId, permissionId, isGranted: true);
// โœ… Permission changes tracked automatically!

Permission Management

๐Ÿš€ Simplified Workflow (Recommended for Development):

# Add [Permission] attributes to entities, then:
dotnet run -- --apply-permissions

๐Ÿ”ง Advanced Workflow (Enterprise/Production):

# Generate migration files:
dotnet run -- --make-permissions
dotnet ef database update

๐Ÿ“š Comprehensive Examples

Explore the complete enterprise features with our detailed examples:

๐Ÿ” Audit Trail Examples

# Run App Architecture audit trail examples
cd examples
dotnet run AuditTrailExample.cs

# Run AspNet Architecture enterprise examples
cd examples
dotnet run AspNetAuditTrailExample.cs

Examples demonstrate:

  • โœ… User Lifecycle Tracking - Create, update, soft delete with automatic audit
  • โœ… Permission Management - 5-level permission system with full audit trail
  • โœ… Session Management - Complete session lifecycle tracking
  • โœ… Login History - Authentication attempt logging with enterprise audit
  • โœ… Group Management - User organization with permission inheritance
  • โœ… Enterprise Integration - ASP.NET Core Identity with advanced audit features

See examples/README.md for detailed documentation and sample output.

๐Ÿ“– Documentation:

๐Ÿงช Testing

The project includes comprehensive test coverage across all implemented features:

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

# Run specific test projects
dotnet test tests/App.Tests/ --filter Category=Entity
dotnet test tests/AspNet.Tests/ --filter Category=Integration
dotnet test tests/Shared.Tests/ --filter Category=Service

Current Test Structure:

  • App.Tests: App architecture entity, integration, and service tests
  • AspNet.Tests: AspNet architecture with Identity integration tests
  • Shared.Tests: CLI commands, permission generation, and shared component tests

๐Ÿ“– Architecture Decision

When to choose App Architecture:

  • ๐ŸŽฏ Simple applications with basic user management needs
  • ๐Ÿš€ Microservices that need lightweight identity
  • ๐ŸŽฎ Console applications or background services
  • ๐Ÿ”ง Custom authentication requirements
  • โšก Performance-critical applications requiring minimal overhead
  • ๐Ÿ”„ High flexibility for custom business logic

When to choose AspNet Architecture:

  • ๐Ÿข Enterprise web applications
  • ๐Ÿ” Complex authentication scenarios (2FA, OAuth, etc.)
  • ๐ŸŒ Web applications using ASP.NET Core Identity features
  • ๐ŸŽญ Role-based and policy-based authorization
  • โš™๏ธ Integration with existing ASP.NET Core Identity systems
  • ๐Ÿ›ก๏ธ Advanced security requirements and compliance needs
  • ๐Ÿ“Š Enterprise audit and reporting requirements

๐Ÿ’ก Need help choosing? See our Architecture Comparison Guide for detailed decision matrices and performance benchmarks.

๐Ÿค Contributing

This project is developed and maintained by Joaquin Lugo Zavala under the Diiwo organization.

Development Guidelines:

  1. Follow established coding patterns from existing implementations
  2. Maintain comprehensive test coverage for all new features
  3. Update documentation for any API changes
  4. Use conventional commit messages
  5. Ensure integration with Diiwo.Core remains clean

๐Ÿ“œ License

MIT License - Copyright ยฉ Joaquin Lugo Zavala 2024-2025

See LICENSE file for details.

๐Ÿ“ž Support & Contact


Built with โค๏ธ for the .NET community

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.2 260 10/26/2025
0.1.1 231 10/23/2025
0.1.0 235 10/22/2025

Version 0.1.2 - Dependency Update:
     - Update Diiwo.Core dependency to version 0.2.0
     - All features from previous versions remain unchanged