文章目录
- .NetCore身份认证组件MiniAuth
-
- 安装MiniAuth组件
- 在Startup/Program配置和启用MiniAuth
- MiniAuth默认配置
- MiniAuth认证类型枚举
- 配置完成,启动项目,访问管理界面
- [管理界面的端口(Endpoints 管理)](#管理界面的端口(Endpoints 管理))
.NetCore身份认证组件MiniAuth
安装MiniAuth组件
install-package MiniAuth
在Startup/Program配置和启用MiniAuth
csharp
var builder = WebApplication.CreateBuilder(args);
//注入MiniAuth(越早注入越好)
builder.Services.AddMiniAuth(miniAuthOption =>
{
//修改认证类型
miniAuthOption.AuthenticationType = AuthType.BearerJwt;
//修改秘钥
miniAuthOption.JWTKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("cvzRqFw9m7HPNePy"));
//修改MiniAuth数据库链接
miniAuthOption.SqliteConnectionString = "Source=lingbug_miniauth_identity.db";
});
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
MiniAuth默认配置
csharp
internal class MiniAuthOption
{
public static string RoutePrefix = "MiniAuth";
public static string LoginPath = $"/{RoutePrefix}/login.html";
public static bool DisableMiniAuthLogin = false;
public static AuthType AuthenticationType = AuthType.Cookie;
public static SecurityKey JWTKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is miniauth key for demo"));
/// <summary>
/// Token expires in seconds, default is 1 hour
/// </summary>
public static int TokenExpiresIn = 60 * 60;
public static string Issuer = $"{RoutePrefix}";
public static string SqliteConnectionString = "Data Source=miniauth_identity.db";
}
MiniAuth认证类型枚举
csharp
public enum AuthType
{
Cookie,
BearerJwt
}
配置完成,启动项目,访问管理界面
- 地址:http://localhost:5025/MiniAuth/index.html
- 注意:首次访问会提示未授权,登录后即可正常访问
- 登录管理界面账号密码:
- 账号:admin@mini-software.github.io
- 密码:E7c4f679-f379-42bf-b547-684d456bc37f(请及时修改密码)
管理界面的端口(Endpoints 管理)
名称 | 路由 |
---|---|
HTTP: POST /MiniAuth/refreshToken | /MiniAuth/refreshToken |
HTTP: POST /MiniAuth/login | /MiniAuth/login |
HTTP: POST /MiniAuth/api/saveUser | /MiniAuth/api/saveUser |
HTTP: POST /MiniAuth/api/saveRole | /MiniAuth/api/saveRole |
HTTP: POST /MiniAuth/api/resetPassword | /MiniAuth/api/resetPassword |
HTTP: POST /MiniAuth/api/getUsers | /MiniAuth/api/getUsers |
HTTP: POST /MiniAuth/api/getConfig | /MiniAuth/api/getConfig |
HTTP: POST /MiniAuth/api/deleteUser | /MiniAuth/api/deleteUser |
HTTP: POST /MiniAuth/api/deleteRole | /MiniAuth/api/deleteRole |
HTTP: GET /MiniAuth/logout | /MiniAuth/logout |
HTTP: GET /MiniAuth/api/getUserInfo | /MiniAuth/api/getUserInfo |
HTTP: GET /MiniAuth/api/getRoles | /MiniAuth/api/getRoles |
HTTP: GET /MiniAuth/api/getAllEndpoints | /MiniAuth/api/getAllEndpoints |
HTTP: GET /MiniAuth/AccessDenied | /MiniAuth/AccessDenied |