增加Shop API
This commit is contained in:
1 parent
3769193696
commit
5d017740c6
83 files changed
+4451
-696
No files matched your search
@@ -29,7 +29,7 @@ namespace Store.Api.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录:校验用户名/密码,签发 JWT(同账号支持多个独立会话)
|
||||
/// 登录:校验用户名/密码,签发数据库 Token(同账号支持多个独立会话)
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
[EndpointSummary("用户登录")]
|
||||
@@ -51,7 +51,9 @@ namespace Store.Api.Controllers
|
||||
new(JwtClaimTypes.UserName, user.UserName),
|
||||
};
|
||||
|
||||
TokenResult token = _tokenService.CreateToken(claims, HttpContext.Connection.RemoteIpAddress?.ToString());
|
||||
if (request.DeviceId?.Length > 100 || request.DeviceName?.Length > 100)
|
||||
return ApiResult.Fail("设备信息最多 100 字符", 400);
|
||||
TokenResult token = _tokenService.CreateToken(claims, HttpContext.Connection.RemoteIpAddress?.ToString(), request.DeviceId, request.DeviceName);
|
||||
return ApiResult.Ok(token);
|
||||
}
|
||||
|
||||
@@ -108,5 +110,7 @@ namespace Store.Api.Controllers
|
||||
public string UserName { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
public string? DeviceId { get; set; }
|
||||
public string? DeviceName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ public partial class Program
|
||||
// 模块服务注册阶段(等价于 builder.Services.AddStoreHub(builder.Configuration, builder.Environment),额外把配置/环境交给模块)
|
||||
builder.AddStore();
|
||||
builder.Services.AddFreeSqlDB();
|
||||
// JWT 验证:注册 JwtBearer 认证 + 令牌服务 + OpenAPI Bearer 安全方案(配置节 Jwt)
|
||||
builder.Services.AddStoreHubJwt(builder.Configuration);
|
||||
// 数据库 Token 认证,配置节 TokenAuth
|
||||
builder.Services.AddStoreHubTokenAuth(builder.Configuration);
|
||||
// Add services to the container.
|
||||
|
||||
//builder.Services.Configure<Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions>(options =>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
{
|
||||
"Jwt": {
|
||||
"TokenAuth": {
|
||||
"DevelopmentToken": {
|
||||
"Enabled": true,
|
||||
"Token": "store-local-dev-7f2c9e4a6b814d38a5910e62c4f837bd",
|
||||
"UserName": "18990991234"
|
||||
"Enabled": true
|
||||
}
|
||||
},
|
||||
"Logging": {
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=192.168.0.200;Port=3306;Database=mysql;Uid=root;Pwd=123456;",
|
||||
},
|
||||
"Jwt": {
|
||||
"Issuer": "StoreHub",
|
||||
"Audience": "StoreHub.Client",
|
||||
"SigningKey": "StoreHub--Smxf8DtV8a5dFdaCVCXtFfWbmMRfw53ectEjr8JvhUjGpPP7fuBdRn",
|
||||
"ExpiresMinutes": 2880,
|
||||
"ClockSkewMinutes": 5,
|
||||
"ValidateIssuer": true,
|
||||
"ValidateAudience": true,
|
||||
"ValidateLifetime": true
|
||||
"TokenAuth": {
|
||||
"IdleDays": 7,
|
||||
"AbsoluteMaxDays": 30,
|
||||
"RenewIntervalMinutes": 10,
|
||||
"CacheSeconds": 30,
|
||||
"MaxDevicesPerUser": 0,
|
||||
"DevelopmentToken": {
|
||||
"Enabled": false,
|
||||
"Token": "store-local-dev-7f2c9e4a6b814d38a5910e62c4f837bd",
|
||||
"UserName": "18990991234"
|
||||
}
|
||||
},
|
||||
"Plugins": {
|
||||
"Path": "Plugins"
|
||||
|
||||
Reference in new issue
Block a user