Sindika.AspNet.Authentication
1.12.4
dotnet add package Sindika.AspNet.Authentication --version 1.12.4
NuGet\Install-Package Sindika.AspNet.Authentication -Version 1.12.4
<PackageReference Include="Sindika.AspNet.Authentication" Version="1.12.4" />
paket add Sindika.AspNet.Authentication --version 1.12.4
#r "nuget: Sindika.AspNet.Authentication, 1.12.4"
// Install Sindika.AspNet.Authentication as a Cake Addin #addin nuget:?package=Sindika.AspNet.Authentication&version=1.12.4 // Install Sindika.AspNet.Authentication as a Cake Tool #tool nuget:?package=Sindika.AspNet.Authentication&version=1.12.4
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. |
-
net9.0
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.1)
- Microsoft.EntityFrameworkCore.Tools (>= 9.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.0)
- Sindika.AspNet.Common (>= 1.6.1)
- 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.12.4 | 169 | 3/19/2025 |
1.12.3 | 210 | 3/11/2025 |
1.12.2 | 149 | 3/11/2025 |
1.12.1 | 154 | 3/11/2025 |
1.12.0 | 144 | 3/11/2025 |
1.11.0 | 207 | 3/11/2025 |
1.10.12 | 164 | 3/10/2025 |
1.10.11 | 153 | 3/10/2025 |
1.10.10 | 238 | 3/7/2025 |
1.10.9 | 195 | 3/7/2025 |
1.10.8 | 268 | 2/24/2025 |
1.10.7 | 104 | 2/20/2025 |
1.10.6 | 139 | 2/17/2025 |
1.10.5 | 101 | 2/14/2025 |
1.10.4 | 94 | 2/7/2025 |
1.10.3 | 93 | 2/6/2025 |
1.10.2 | 356 | 2/5/2025 |
1.10.1 | 151 | 2/3/2025 |
1.10.0 | 103 | 2/2/2025 |
1.9.3 | 104 | 2/2/2025 |
1.9.2 | 88 | 1/31/2025 |
1.9.1 | 95 | 1/31/2025 |
1.9.0 | 95 | 1/31/2025 |
1.8.0 | 99 | 1/30/2025 |
1.7.0 | 89 | 1/30/2025 |
1.6.0 | 112 | 1/30/2025 |
1.5.1 | 94 | 1/24/2025 |
1.5.0 | 86 | 1/23/2025 |
1.4.2 | 89 | 1/22/2025 |
1.4.1 | 86 | 1/22/2025 |
1.4.0 | 82 | 1/22/2025 |
1.3.1 | 91 | 1/21/2025 |
1.3.0 | 85 | 1/21/2025 |
1.2.0 | 95 | 1/20/2025 |
1.1.1 | 85 | 1/19/2025 |
1.1.0 | 81 | 1/19/2025 |
1.0.0 | 87 | 1/18/2025 |