fix(#I1BMCY): 修复 JWT 认证 Token 配置不生效问题
#Comment comment #I1BMCY #Issue close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I1BMCY
This commit is contained in:
parent
a9ae7ed140
commit
03cc7d445c
|
@ -13,7 +13,7 @@
|
|||
<PackageReference Include="Longbow.Logging" Version="3.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
|
||||
<PackageReference Include="Sentry.AspNetCore" Version="2.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -5,6 +5,7 @@ using Longbow.Web.Mvc;
|
|||
using Longbow.Web.SMS;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bootstrap.Admin.Controllers.Api
|
||||
|
@ -29,17 +30,25 @@ namespace Bootstrap.Admin.Controllers.Api
|
|||
/// <summary>
|
||||
/// JWT 登陆认证接口
|
||||
/// </summary>
|
||||
/// <param name="config"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public string? Post([FromBody]User user)
|
||||
public string? Post([FromServices]IConfiguration config, [FromBody]User user)
|
||||
{
|
||||
var token = string.Empty;
|
||||
string userName = user.UserName;
|
||||
string password = user.Password;
|
||||
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, password))
|
||||
{
|
||||
token = BootstrapAdminJwtTokenHandler.CreateToken(userName);
|
||||
token = BootstrapAdminJwtTokenHandler.CreateToken(userName, op =>
|
||||
{
|
||||
var tokenOption = config.GetOption(() => new TokenValidateOption());
|
||||
op.Audience = tokenOption.Audience;
|
||||
op.Expires = tokenOption.Expires;
|
||||
op.Issuer = tokenOption.Issuer;
|
||||
op.SecurityKey = tokenOption.SecurityKey;
|
||||
});
|
||||
}
|
||||
HttpContext.Log(userName, !string.IsNullOrEmpty(token));
|
||||
return token;
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" />
|
||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.2-beta01" />
|
||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.2" />
|
||||
<PackageReference Include="Longbow" Version="3.1.0" />
|
||||
<PackageReference Include="Longbow.AlipayAuth" Version="3.1.0" />
|
||||
<PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" />
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" />
|
||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.2-beta01" />
|
||||
<PackageReference Include="Bootstrap.Security.Mvc" Version="3.1.2" />
|
||||
<PackageReference Include="Longbow" Version="3.1.0" />
|
||||
<PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" />
|
||||
<PackageReference Include="Longbow.Data" Version="3.1.0" />
|
||||
|
|
Loading…
Reference in New Issue