Diiwo.Identity
0.1.2
dotnet add package Diiwo.Identity --version 0.1.2
NuGet\Install-Package Diiwo.Identity -Version 0.1.2
<PackageReference Include="Diiwo.Identity" Version="0.1.2" />
<PackageVersion Include="Diiwo.Identity" Version="0.1.2" />
<PackageReference Include="Diiwo.Identity" />
paket add Diiwo.Identity --version 0.1.2
#r "nuget: Diiwo.Identity, 0.1.2"
#:package Diiwo.Identity@0.1.2
#addin nuget:?package=Diiwo.Identity&version=0.1.2
#tool nuget:?package=Diiwo.Identity&version=0.1.2
๐ฏ DIIWO Identity Solution
Dual-architecture identity management library for modern .NET applications
๐๏ธ 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
- App Architecture: Complete standalone implementation (
๐ Enterprise Audit Trail System โญ NEW
- Automatic audit tracking -
CreatedAt,UpdatedAt,CreatedBy,UpdatedByfields managed automatically - Soft delete support - Entities marked as
Terminatedinstead of hard deletion - Entity state management - Track entity lifecycle with
EntityStateenum - 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
/examplesdirectory
- Automatic audit tracking -
๐ 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/andtests/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
- Organized
๐ 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
Terminatedinstead of permanent deletion - ๐ State Management: Track entity lifecycle with
EntityStateenum (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:
- Architecture Comparison Guide - Choose between App vs AspNet architectures
- Implementation Examples - Enterprise patterns and code examples
- Simplified Workflow Guide - One-command approach
- Examples and Usage - Complete examples and best practices
๐งช 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:
- Follow established coding patterns from existing implementations
- Maintain comprehensive test coverage for all new features
- Update documentation for any API changes
- Use conventional commit messages
- Ensure integration with Diiwo.Core remains clean
๐ License
MIT License - Copyright ยฉ Joaquin Lugo Zavala 2024-2025
See LICENSE file for details.
๐ Support & Contact
- Author: Joaquin Lugo Zavala
- GitHub: @JacobMCfly
- Organization: Diiwo
- Repository: diiwo/diiwo-identity
- Core Dependency: diiwo/diiwo-core
Built with โค๏ธ for the .NET community
| Product | Versions 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. |
-
net8.0
- BCrypt.Net-Next (>= 4.0.3)
- Diiwo.Core (>= 0.2.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 8.0.0)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 8.0.0)
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.EntityFrameworkCore.Design (>= 8.0.0)
- Microsoft.EntityFrameworkCore.InMemory (>= 8.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.IdentityModel.Tokens (>= 8.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.0)
- System.IdentityModel.Tokens.Jwt (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version 0.1.2 - Dependency Update:
- Update Diiwo.Core dependency to version 0.2.0
- All features from previous versions remain unchanged