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" />
                    
Directory.Packages.props
<PackageReference Include="AuthMicroservice.Core" />
                    
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 AuthMicroservice.Core --version 1.0.2
                    
#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
                    
Install as a Cake Addin
#tool nuget:?package=AuthMicroservice.Core&version=1.0.2
                    
Install as a Cake Tool

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 user
  • POST /api/auth/login - Login
  • POST /api/auth/refresh - Refresh token
  • POST /api/auth/revoke - Revoke token
  • GET /api/auth/me - Get current user
  • POST /api/externalauth/google - Google OAuth
  • POST /api/externalauth/github - GitHub OAuth
  • GET /api/roles - List roles
  • GET /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

Product 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.

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.0.2 717 12/1/2025
1.0.1 148 11/1/2025

Initial release with JWT authentication, ABAC authorization, external OAuth support (Google, GitHub), and extensible policy system.