# MiniAuth **Repository Path**: lemon_soda/MiniAuth ## Basic Information - **Project Name**: MiniAuth - **Description**: MiniAuth 轻量 ASP.NET Core Identity Web 后台管理插件 - **Primary Language**: C# - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: https://github.com/mini-software/MiniAuth - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 27 - **Created**: 2024-05-28 - **Last Updated**: 2024-05-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README

NuGet star GitHub stars version

---

English | 简体中文 | 繁體中文 | 日本語 | 한국어 | Español

---
Your Star, Donate, Recomm. can make MiniAuth better
### Introduction "One-line code" adds identity management web for your new/old projects
Image 1 Image 2
Image 3 Image 4
### Features - Compatibility: Based JWT, Cookie, and Session that follow the .NET Identity standard. - Out of the box: Easy integration, MiniAuth works with APIs, MVC, Razor Pages. - Multi-platform: Supports Linux, macOS environments. - Multiple Database Support: Compatible with any database that follow the Identity EF Core standard. ### Installation Install the package from [NuGet](https://www.nuget.org/packages/MiniAuth): ``` dotnet add package MiniAuth // or NuGet\Install-Package MiniAuth ``` ### Quick Start Add a single line of code `services.AddMiniAuth()` in Startup, then run your project. Example: ```csharp public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); builder.Services.AddMiniAuth(); var app = builder.Build(); app.Run(); } } ``` The default admin account is `admin@mini-software.github.io` with the password `E7c4f679-f379-42bf-b547-684d456bc37f` (remember to change the password). The admin page can be accessed at `http(s)://yourhost/miniauth/index.html`. Note: If you already have your own identity auth, please follow the instructions below. ### Existing Identity Setup Turn off autoUse for `AddMiniAuth`, and replace it with your own IdentityDBContext, user, and permission authentication in UseMiniAuth, placing it after your own Auth. Example: ```csharp public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); builder.Services.AddDbContext(options => options.UseSqlServer(connectionString)); builder.Services.AddDatabaseDeveloperPageExceptionFilter(); builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddRoles() .AddEntityFrameworkStores(); builder.Services.AddControllersWithViews(); builder.Services.AddMiniAuth(autoUse: false); // <= ❗❗❗ var app = builder.Build(); app.UseMiniAuth(); // <= ❗❗❗ app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.MapRazorPages(); app.Run(); } ``` #### Order Matters Please place UseMiniAuth after routing generation; otherwise, the system won't be able to obtain routing data for permission checks, like: ```csharp app.UseRouting(); app.UseMiniAuth(); ``` #### Note: Adding Role Rules Please add `AddRoles()`; otherwise `[Authorize(Roles = "YourRole")]` won't work. ```C# builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddRoles() // ❗❗❗ .AddEntityFrameworkStores(); ``` #### Disable MiniAuth Login If you only want to use your own login logic, page, and API, you can custom the login path and turn off the switch. ```C# // before add service MiniAuthOptions.LoginPath = "/Identity/Account/Login"; MiniAuthOptions.DisableMiniAuthLogin = true; ``` ### Changing Databases MiniAuth system defaults to using SQLite without any code settings required. If you need to switch, specify a different database type in `app.UseMiniAuth`. ### Configuration and Options #### Default Mode - MiniAuth operates in a default mode where IT Admin centrally manages user operations like registration and password reset, requiring an Admin privilege account to perform these actions. Default Role = miniauth-admin. #### Login and User Validation For non-ApiController, login redirects to the login.html page (determined by Headers["X-Requested-With"] == "XMLHttpRequest" or ApiControllerAttribute). ApiController Controllers do not redirect to the login page by default but return a 401 status code. ### Distributed Systems - Please switch the database source to SQL Server, MySQL, PostgreSQL, etc. ### Custom Frontend - The management backend front-end uses Vue3 + Vite at `/src/Frontend_Identity`. You can update the miniauth UI after using `npm run build`. - If you do not want to use the miniauth default for the login page, you can use the identity scaffolded Login.cshtml in mvc, or change the login.html, js, css of the miniauth frontend. ### Release Notes Refer to the [Release Notes](releases) for updates. ### TODO Link: [MiniAuth.Identify project](https://github.com/orgs/mini-software/projects/7/views/1)