fix(#I1BMCY): 修复 JWT 认证 Token 配置不生效问题

#Comment
comment #I1BMCY

#Issue
close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I1BMCY
This commit is contained in:
Argo Zhang 2020-03-14 13:34:10 +08:00
parent a9ae7ed140
commit 03cc7d445c
No known key found for this signature in database
GPG Key ID: 152E398953DDF19F
4 changed files with 14 additions and 5 deletions

View File

@ -13,7 +13,7 @@
<PackageReference Include="Longbow.Logging" Version="3.1.1" /> <PackageReference Include="Longbow.Logging" Version="3.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
<PackageReference Include="Sentry.AspNetCore" Version="2.1.0" /> <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>
<ItemGroup> <ItemGroup>

View File

@ -5,6 +5,7 @@ using Longbow.Web.Mvc;
using Longbow.Web.SMS; using Longbow.Web.SMS;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Bootstrap.Admin.Controllers.Api namespace Bootstrap.Admin.Controllers.Api
@ -29,17 +30,25 @@ namespace Bootstrap.Admin.Controllers.Api
/// <summary> /// <summary>
/// JWT 登陆认证接口 /// JWT 登陆认证接口
/// </summary> /// </summary>
/// <param name="config"></param>
/// <param name="user"></param> /// <param name="user"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
public string? Post([FromBody]User user) public string? Post([FromServices]IConfiguration config, [FromBody]User user)
{ {
var token = string.Empty; var token = string.Empty;
string userName = user.UserName; string userName = user.UserName;
string password = user.Password; string password = user.Password;
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password) && UserHelper.Authenticate(userName, 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)); HttpContext.Log(userName, !string.IsNullOrEmpty(token));
return token; return token;

View File

@ -6,7 +6,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" /> <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" Version="3.1.0" />
<PackageReference Include="Longbow.AlipayAuth" Version="3.1.0" /> <PackageReference Include="Longbow.AlipayAuth" Version="3.1.0" />
<PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" /> <PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" />

View File

@ -6,7 +6,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="3.1.1" /> <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" Version="3.1.0" />
<PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" /> <PackageReference Include="Longbow.Cache" Version="3.1.2-beta-02" />
<PackageReference Include="Longbow.Data" Version="3.1.0" /> <PackageReference Include="Longbow.Data" Version="3.1.0" />