Skip to content

GrydAuth Module ​

See Remote consumer and separated authority for the registration and migration changes in the next release. See Profile image processing for image formats, validation limits, animation behavior, and native host packaging. See Password reset email delivery for SMTP configuration and delivery behavior. See Read-only readers for host composition without the authentication or write stack.

GrydAuth is a complete authentication and authorization module for .NET applications. It provides JWT/OAuth2 authentication, role-based access control (RBAC), permission-based authorization, and multi-tenancy support out of the box.

✨ Features ​

FeatureDescription
🔐 JWT AuthenticationComplete JWT token lifecycle with access/refresh tokens
👥 User ManagementUser registration, authentication, password management
🎭 Role-Based AccessFlexible role system with hierarchical permissions
🔑 Permission SystemGranular permission-based authorization with policies
🏢 Multi-TenancyBuilt-in support for tenant isolation and federation
🌐 FederationGoogle, Microsoft and Apple social providers, plus enterprise OIDC connections
📍 Security FeaturesRate limiting, audit logging, geo-location tracking
🔄 Token InvalidationReal-time token blacklisting and version control

📦 Packages ​

GrydAuth is organized in multiple packages following Clean Architecture:

📦 GrydAuth
├── GrydAuth.Domain           # Entities, Value Objects, Domain Events
├── GrydAuth.Application      # Commands, Queries, Interfaces
├── GrydAuth.Infrastructure   # JWT, Repositories, External Services
└── GrydAuth.API              # Controllers, Middlewares, Filters

🚀 Quick Start ​

For a new Auth API, use the maintained gryd-api template with --IncludeAuth true. The Getting Started guide links its exact composition root and README, including controller discovery, API versioning, PostgreSQL configuration, Development migrations, and local secret setup. The template is compiled by the repository's template validation workflow.

🏗️ Architecture Overview ​

┌─────────────────────────────────────────────────────────────────┐
│                       GrydAuth.API                              │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────────┐ │
│  │ Controllers │  │ Middlewares │  │ Exception Handlers      │ │
│  └─────────────┘  └─────────────┘  └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                    GrydAuth.Application                         │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────────┐ │
│  │  Commands   │  │   Queries   │  │     Interfaces          │ │
│  │  - Login    │  │ - GetUser   │  │ - IAuthService          │ │
│  │  - Register │  │ - GetRoles  │  │ - ITokenService         │ │
│  │  - Refresh  │  │ - GetPerms  │  │ - IPermissionService    │ │
│  └─────────────┘  └─────────────┘  └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                   GrydAuth.Infrastructure                       │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────────┐ │
│  │   JWT Svc   │  │ Repositories│  │ Permission Handler      │ │
│  │ - Generate  │  │ - User      │  │ - Policy Provider       │ │
│  │ - Validate  │  │ - Role      │  │ - Auth Handler          │ │
│  │ - Refresh   │  │ - Tenant    │  │ - Claim Builder         │ │
│  └─────────────┘  └─────────────┘  └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                      GrydAuth.Domain                            │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────────────┐ │
│  │  Entities   │  │Value Objects│  │    Domain Events        │ │
│  │  - User     │  │ - Email     │  │ - UserCreatedEvent      │ │
│  │  - Role     │  │ - Password  │  │ - RoleAssignedEvent     │ │
│  │  - Tenant   │  │ - Token     │  │ - PermissionChanged     │ │
│  └─────────────┘  └─────────────┘  └─────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘

📊 Entity Relationship Diagram ​

The following diagram shows the complete data model for GrydAuth, including all entities and their relationships:

100% 💡 Use Ctrl + Scroll para zoom | Arraste para navegar

Entity Descriptions ​

EntityTypeDescription
UserAggregate RootGlobal user entity, not tied to specific tenants
TenantAggregate RootOrganization/company in multi-tenancy system
UserTenantAggregate RootUser-Tenant relationship with roles and permissions
RoleAggregate RootGroups permissions together (tenant-scoped)
PermissionAggregate RootDefines actions that can be performed (tenant-scoped)
UserRoleEntityLinks UserTenant to Role
UserPermissionEntityDirect permission assignment to UserTenant
RolePermissionEntityLinks Role to Permission (tenant-scoped)
UserAppIdEntityMulti-app support - links User to application IDs
UserPasswordHistoryEntityPassword history for reuse prevention
FailedLoginAttemptEntitySecurity tracking for brute-force protection
PasswordResetTokenEntityToken for password reset flow
UserPreferenceEntityUser-specific settings per tenant (theme, language, sidebar state, etc.)
UserMenuFavoriteEntityBookmarked menu items with custom display order per tenant

Key Relationships ​

  1. User ↔ Tenant (Many-to-Many via UserTenant)

    • Users exist globally, not tied to tenants
    • UserTenant manages the relationship with roles/permissions per tenant
  2. Role ↔ Permission (Many-to-Many via RolePermission)

    • Roles group permissions together
    • Both are tenant-scoped
  3. UserTenant ↔ Role/Permission

    • Users can have roles AND direct permissions per tenant
    • Permissions are evaluated from both sources
  4. User ↔ AppId (One-to-Many)

    • Users can access multiple applications
    • AppId is validated during login
  5. User ↔ UserPreference (One-to-Many, Tenant-Scoped)

    • Each user can have multiple preferences per tenant
    • Unique constraint on (UserId, TenantId, Key)
    • Used for storing settings like theme, language, sidebar state
  6. User ↔ UserMenuFavorite (One-to-Many, Tenant-Scoped)

    • Each user can bookmark multiple menu items per tenant
    • Unique constraint on (UserId, TenantId, MenuItemId)
    • Ordered by customizable DisplayOrder

API Endpoints Documentation

For a complete reference of all REST API endpoints with request/response schemas, authentication requirements, and examples:

📖 Documentation Sections ​

Released under the MIT License.