NAuth.DTO 0.2.4

Suggested Alternatives

NAuth

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package NAuth.DTO --version 0.2.4
                    
NuGet\Install-Package NAuth.DTO -Version 0.2.4
                    
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="NAuth.DTO" Version="0.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NAuth.DTO" Version="0.2.4" />
                    
Directory.Packages.props
<PackageReference Include="NAuth.DTO" />
                    
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 NAuth.DTO --version 0.2.4
                    
#r "nuget: NAuth.DTO, 0.2.4"
                    
#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 NAuth.DTO@0.2.4
                    
#: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=NAuth.DTO&version=0.2.4
                    
Install as a Cake Addin
#tool nuget:?package=NAuth.DTO&version=0.2.4
                    
Install as a Cake Tool

NAuth.DTO

NuGet NuGet Downloads License: MIT

Data Transfer Objects (DTOs) library for NAuth authentication and authorization system. Contains all data models, settings, and converters used across NAuth components for user management, roles, and authentication.

📦 Installation

Install via NuGet Package Manager:

dotnet add package NAuth.DTO

Or via Package Manager Console:

Install-Package NAuth.DTO

✨ Features

  • User DTOs: Complete user data models for authentication and management
  • Role DTOs: Role and permission data structures
  • Authentication Models: Login parameters, token results, and password management
  • Settings: Configuration objects for NAuth services
  • Converters: Custom JSON converters for proper serialization
  • Validation: Built-in validation attributes and structures
  • .NET 8 Compatible: Built for modern .NET applications

📚 Core Components

User Models

UserInfo

Complete user information including profile, roles, addresses, and phones.

public class UserInfo
{
    public long UserId { get; set; }
    public string Slug { get; set; }
    public string ImageUrl { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public string Hash { get; set; }
    public bool IsAdmin { get; set; }
    public DateTime? BirthDate { get; set; }
    public string IdDocument { get; set; }
    public string PixKey { get; set; }
    public string Password { get; set; }
    public int Status { get; set; }
    public IList<RoleInfo> Roles { get; set; }
    public IList<UserPhoneInfo> Phones { get; set; }
    public IList<UserAddressInfo> Addresses { get; set; }
    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; }
}
UserInsertedInfo

Simplified model for user registration (without system-generated fields).

public class UserInsertedInfo
{
    public string Slug { get; set; }
    public string ImageUrl { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
    public bool IsAdmin { get; set; }
    public DateTime? BirthDate { get; set; }
    public string IdDocument { get; set; }
    public string PixKey { get; set; }
    public string Password { get; set; }
    public IList<RoleInfo> Roles { get; set; }
    public IList<UserPhoneInfo> Phones { get; set; }
    public IList<UserAddressInfo> Addresses { get; set; }
}
LoginParam

Authentication credentials.

public class LoginParam
{
    public string Email { get; set; }
    public string Password { get; set; }
}
UserTokenResult

Authentication result with user info and JWT token.

public class UserTokenResult
{
    public string Token { get; set; }
    public UserInfo User { get; set; }
}

Password Management

ChangePasswordParam

Change password with current password verification.

public class ChangePasswordParam
{
    [JsonPropertyName("oldPassword")]
    public string OldPassword { get; set; }
    
    [JsonPropertyName("newPassword")]
    public string NewPassword { get; set; }
}
ChangePasswordUsingHashParam

Reset password using recovery hash.

public class ChangePasswordUsingHashParam
{
    [JsonPropertyName("recoveryHash")]
    public string RecoveryHash { get; set; }
    
    [JsonPropertyName("newPassword")]
    public string NewPassword { get; set; }
}

Role Models

RoleInfo

Role information with permissions.

public class RoleInfo
{
    public long RoleId { get; set; }
    public string Slug { get; set; }
    public string Name { get; set; }
}

Search and Pagination

UserSearchParam

Parameters for user search.

public class UserSearchParam
{
    public string SearchTerm { get; set; }
    public int Page { get; set; }
    public int PageSize { get; set; }
}
PagedResult<T>

Generic paged result container.

public class PagedResult<T>
{
    public IList<T> Items { get; set; }
    public int Page { get; set; }
    public int PageSize { get; set; }
    public int TotalCount { get; set; }
    public int TotalPages { get; }
    public bool HasPreviousPage { get; }
    public bool HasNextPage { get; }
}

Settings

NAuthSetting

Configuration settings for NAuth services.

public class NAuthSetting
{
    public string ApiUrl { get; set; }
    public string JwtSecret { get; set; }
    public string BucketName { get; set; }
}

💻 Usage Examples

Basic User Model Usage

using NAuth.DTO.User;

// Create a new user for registration
var newUser = new UserInsertedInfo
{
    Name = "John Doe",
    Email = "john.doe@example.com",
    Password = "SecureP@ssw0rd",
    BirthDate = new DateTime(1990, 1, 1),
    IdDocument = "12345678901",
    Roles = new List<RoleInfo>
    {
        new RoleInfo { RoleId = 1, Slug = "user", Name = "User" }
    },
    Phones = new List<UserPhoneInfo>
    {
        new UserPhoneInfo { Phone = "5511999999999" }
    },
    Addresses = new List<UserAddressInfo>
    {
        new UserAddressInfo
        {
            ZipCode = "01234567",
            Address = "123 Main St",
            Complement = "Apt 101",
            Neighborhood = "Downtown",
            City = "São Paulo",
            State = "SP"
        }
    }
};

Login Example

using NAuth.DTO.User;

// Prepare login credentials
var loginParam = new LoginParam
{
    Email = "john.doe@example.com",
    Password = "SecureP@ssw0rd"
};

// After successful authentication, you receive:
var tokenResult = new UserTokenResult
{
    Token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    User = userInfo
};

Password Management

using NAuth.DTO.User;

// Change password (authenticated user)
var changePassword = new ChangePasswordParam
{
    OldPassword = "OldP@ssw0rd",
    NewPassword = "NewP@ssw0rd123"
};

// Reset password using recovery hash
var resetPassword = new ChangePasswordUsingHashParam
{
    RecoveryHash = "abc123def456",
    NewPassword = "NewP@ssw0rd123"
};

Pagination Example

using NAuth.DTO.User;

// Search users with pagination
var searchParam = new UserSearchParam
{
    SearchTerm = "john",
    Page = 1,
    PageSize = 20
};

// Results come in a paged format
var results = new PagedResult<UserInfo>
{
    Items = userList,
    Page = 1,
    PageSize = 20,
    TotalCount = 150
};

Console.WriteLine($"Showing page {results.Page} of {results.TotalPages}");
Console.WriteLine($"Has next page: {results.HasNextPage}");

🔐 JSON Serialization

All DTOs are properly decorated with JSON attributes for seamless serialization with both Newtonsoft.Json and System.Text.Json:

[JsonPropertyName("userId")]
public long UserId { get; set; }

[JsonPropertyName("email")]
public string Email { get; set; }

Custom Converters

The library includes custom converters for special cases:

NullableDateTimeConverter

Handles nullable DateTime serialization properly.

[JsonConverter(typeof(NullableDateTimeConverter))]
public DateTime? BirthDate { get; set; }

📊 User Status Enum

User status values for account state management:

public enum UserStatus
{
    Active = 1,
    Inactive = 2,
    Suspended = 3,
    Blocked = 4
}
  • NAuth.ACL: Access Control Layer client library for consuming NAuth services
  • NAuth.API: REST API implementation for authentication services
  • NAuth.Domain: Business logic and domain models

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

💬 Support

For issues, questions, or contributions, please visit the GitHub repository.


Made with ❤️ by Rodrigo Landim at Emagine

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