AuthMicroservice.Core
1.0.2
dotnet add package AuthMicroservice.Core --version 1.0.2
NuGet\Install-Package AuthMicroservice.Core -Version 1.0.2
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="AuthMicroservice.Core" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AuthMicroservice.Core" Version="1.0.2" />
<PackageReference Include="AuthMicroservice.Core" />
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 AuthMicroservice.Core --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AuthMicroservice.Core, 1.0.2"
#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 AuthMicroservice.Core@1.0.2
#: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=AuthMicroservice.Core&version=1.0.2
#tool nuget:?package=AuthMicroservice.Core&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AuthMicroservice
ASP.NET Core authentication & authorization template with JWT, refresh tokens, role/claim management, and external OAuth support (Google, GitHub).
Features
- JWT + Refresh Token authentication
- Role & Claim-based authorization
- Policy-based access control (ABAC)
- External OAuth (Google, GitHub)
- Clean Architecture structure
- Easy configuration via fluent API
Installation
dotnet add package AuthMicroservice
Quick Start
Program.cs:
using AuthMicroservice.Core.Extensions;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthMicroservice(options =>
{
options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection")!;
options.Jwt.Secret = builder.Configuration["Jwt:Secret"]!;
options.Jwt.Issuer = "YourApp";
options.Jwt.Audience = "YourAppUsers";
// Optional: External OAuth
options.ExternalProviders.Google.Enabled = true;
options.ExternalProviders.Google.ClientId = builder.Configuration["Google:ClientId"]!;
options.ExternalProviders.Google.ClientSecret = builder.Configuration["Google:ClientSecret"]!;
});
builder.Services.AddControllers();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
appsettings.json:
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Database=authdb;Username=postgres;Password=yourpassword"
},
"Jwt": {
"Secret": "YOUR_SECRET_KEY_AT_LEAST_32_CHARACTERS_LONG",
"Issuer": "YourApp",
"Audience": "YourAppUsers"
}
}
Run Migrations:
dotnet ef migrations add InitialCreate
dotnet ef database update
Usage
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
[ApiController]
[Route("api/[controller]")]
public class MyController : ControllerBase
{
[Authorize]
[HttpGet("profile")]
public IActionResult GetProfile()
{
var userId = User.FindFirst("user_id")?.Value;
return Ok(new { userId });
}
[Authorize(Roles = "Admin")]
[HttpGet("admin")]
public IActionResult AdminOnly()
{
return Ok("Admin access granted");
}
}
API Endpoints
After installation, built-in endpoints are available:
POST /api/auth/register- Register new userPOST /api/auth/login- LoginPOST /api/auth/refresh- Refresh tokenPOST /api/auth/revoke- Revoke tokenGET /api/auth/me- Get current userPOST /api/externalauth/google- Google OAuthPOST /api/externalauth/github- GitHub OAuthGET /api/roles- List rolesGET /api/users/{userId}/claims- Get user claims
Configuration Options
builder.Services.AddAuthMicroservice(options =>
{
// JWT
options.Jwt.ExpirationMinutes = 60;
options.RefreshToken.ExpirationDays = 7;
// Password requirements
options.Identity.Password.RequiredLength = 8;
options.Identity.Password.RequireDigit = true;
// External providers (optional)
options.ExternalProviders.Google.Enabled = true;
options.ExternalProviders.GitHub.Enabled = true;
// Logging
options.Logging.EnableDetailedLogs = false; // true for development
});
Custom Policies
builder.Services.AddAuthMicroservice(options => { /* ... */ })
.AddCustomPolicy("IsCompanyOwner", policy =>
{
policy.RequireClaim("company_role", "owner");
});
Then use:
[Authorize(Policy = "IsCompanyOwner")]
[HttpDelete("company/{id}")]
public IActionResult DeleteCompany(string id) { /* ... */ }
Project Structure
AuthMicroservice/
├── Core/ # Configuration & Extensions
├── Domain/ # Entities (User, RefreshToken)
├── Application/ # Services, DTOs, Authorization
├── Infrastructure/# EF Core, Database
└── Shared/ # Constants (Roles, Policies, ClaimTypes)
License
MIT License - see LICENSE.txt
Author
Emirhan Yaman
- GitHub: @yamanemirhan
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- AspNet.Security.OAuth.GitHub (>= 9.0.0)
- AuthMicroservice.Application (>= 1.0.2)
- AuthMicroservice.Domain (>= 1.0.2)
- AuthMicroservice.Infrastructure (>= 1.0.2)
- AuthMicroservice.Shared (>= 1.0.0)
- Microsoft.AspNetCore.Authentication.Google (>= 9.0.0)
- Microsoft.AspNetCore.Authentication.JwtBearer (>= 9.0.0)
- Microsoft.AspNetCore.Identity.EntityFrameworkCore (>= 9.0.0)
- Microsoft.Extensions.Http (>= 9.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.
Initial release with JWT authentication, ABAC authorization, external OAuth support (Google, GitHub), and extensible policy system.