Sindika.AspNet.Authentication
1.14.5
dotnet add package Sindika.AspNet.Authentication --version 1.14.5
NuGet\Install-Package Sindika.AspNet.Authentication -Version 1.14.5
<PackageReference Include="Sindika.AspNet.Authentication" Version="1.14.5" />
<PackageVersion Include="Sindika.AspNet.Authentication" Version="1.14.5" />
<PackageReference Include="Sindika.AspNet.Authentication" />
paket add Sindika.AspNet.Authentication --version 1.14.5
#r "nuget: Sindika.AspNet.Authentication, 1.14.5"
#:package Sindika.AspNet.Authentication@1.14.5
#addin nuget:?package=Sindika.AspNet.Authentication&version=1.14.5
#tool nuget:?package=Sindika.AspNet.Authentication&version=1.14.5
Sindika.AspNet.Authentication
Sindika.AspNet.Authentication is a library designed to facilitate authentication in ASP.NET applications. It provides a robust structure for handling user authentication, roles, and permissions.
Features
- DataContext: Predefined data context for easy database integration.
- Entities: Comprehensive entity models for authentication.
- Middleware: Middleware support for seamless integration.
- Seed: Built-in data seeding for initial setup.
Installation
To install the library, use the following command:
> dotnet add package Sindika.AspNet.Authentication
Usage
1. Configure Services
Register the required services in your Program.cs file:
builder.Services.AddDbAuthorization();
2. Extend AuthContext
Create your custom context by extending AuthContext:
public class MyApplicationContext : AuthContext
{
public MyApplicationContext(DbContextOptions<AuthContext> options)
: base(options)
{
}
}
3. Alter UserUserType for Custom Use Cases
Define custom user type relationships by extending UserUserType. For example:
using System.ComponentModel.DataAnnotations.Schema;
using Sindika.AspNet.Authentication.Entities;
namespace Sindika.AspNet.App004.Domain.Entities
{
public class DeveloperUserType : UserUserType, IBaseEntity
{
[Column("user_usertype_developerid")]
public Guid? DeveloperId { get; set; }
[ForeignKey(nameof(DeveloperId))]
public Developer? Developer { get; set; }
}
}
4. Define Custom Entities
Here is an example of a custom entity:
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Sindika.AspNet.App004.Domain.Entities
{
[Table("dbs004_developer")]
public class Developer : IBaseEntity
{
[Key]
[Column("developer_id")]
public Guid Id { get; set; }
[Column("developer_name")]
[MaxLength(255)]
public string Name { get; set; } = string.Empty;
[Column("developer_code")]
[MaxLength(255)]
public string Code { get; set; } = string.Empty;
[Column("developer_phone")]
public string Phone { get; set; } = string.Empty;
[Column("developer_isactive")]
public bool IsActive { get; set; } = true;
[Column("developer_createddate")]
public DateTimeOffset CreatedDate { get; set; } = DateTimeOffset.UtcNow;
[Column("developer_updateddate")]
public DateTimeOffset? UpdatedDate { get; set; }
[Column("developer_deleteddate")]
public DateTimeOffset? DeletedDate { get; set; }
[Column("developer_createdby")]
public string? CreatedBy { get; set; }
[Column("developer_updatedby")]
public string? UpdatedBy { get; set; }
[Column("developer_deletedby")]
public string? DeletedBy { get; set; }
}
}
5. Register Custom Entities
Register your custom entities in the MyApplicationContext class:
public DbSet<DeveloperUserType> DeveloperUserTypes => Set<DeveloperUserType>();
public DbSet<Developer> Developers => Set<Developer>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<DeveloperUserType>().ToTable(USER_USERTYPE_TABLENAME);
modelBuilder.Entity<DeveloperUserType>().HasIndex(c => new { c.DeveloperId });
modelBuilder.Entity<Developer>().HasIndex(c => new { c.IsActive, c.Code });
}
6. Seed Data
Use the provided SeederService to populate initial data:
public class SeederService : IHostedService
{
private readonly IServiceProvider _serviceProvider;
private readonly ILogger<SeederService> _logger;
public SeederService(IServiceProvider serviceProvider, ILogger<SeederService> logger)
{
_serviceProvider = serviceProvider;
_logger = logger;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
using var scope = _serviceProvider.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<AuthContext>();
SeedData(context);
await Task.CompletedTask;
}
private void SeedData(AuthContext context)
{
if (!context.Languages.Any())
{
var languages = new[]
{
new Language { Code = "EN", Name = "English" },
new Language { Code = "ID", Name = "Indonesia" }
};
context.Languages.AddRange(languages);
context.SaveChanges();
_logger.LogInformation($"Seeded {languages.Length} languages.");
}
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
Contributing
Contributions are welcome! Feel free to submit issues or pull requests.
License
This project is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- BCrypt.Net-Next (>= 4.0.3)
- Konscious.Security.Cryptography.Argon2 (>= 1.3.1)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.1)
- Microsoft.EntityFrameworkCore.Tools (>= 9.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.0)
- Sindika.AspNet.Common (>= 1.10.6)
- Sindika.AspNet.Connection (>= 1.0.0)
- Sindika.AspNet.Exception (>= 1.0.0)
- Sindika.AspNet.SecretManager (>= 1.0.1)
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 |
|---|---|---|
| 1.14.5 | 123 | 1/13/2026 |
| 1.14.4 | 559 | 12/19/2025 |
| 1.14.3 | 468 | 12/10/2025 |
| 1.14.2 | 439 | 12/10/2025 |
| 1.14.1 | 446 | 12/10/2025 |
| 1.14.0 | 446 | 12/10/2025 |
| 1.13.0 | 328 | 10/8/2025 |
| 1.12.11 | 181 | 10/7/2025 |
| 1.12.10 | 304 | 9/22/2025 |
| 1.12.9 | 237 | 9/22/2025 |
| 1.12.8 | 265 | 9/22/2025 |
| 1.12.7 | 421 | 8/1/2025 |
| 1.12.6 | 266 | 7/18/2025 |
| 1.12.5 | 181 | 6/26/2025 |
| 1.12.4 | 1,031 | 3/19/2025 |
| 1.12.3 | 282 | 3/11/2025 |
| 1.12.2 | 232 | 3/11/2025 |
| 1.12.1 | 230 | 3/11/2025 |
| 1.12.0 | 226 | 3/11/2025 |
| 1.11.0 | 361 | 3/11/2025 |