From 03cc7d445c67375659a2ddec2a59e37f6c1c6dec Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Sat, 14 Mar 2020 13:34:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(#I1BMCY):=20=E4=BF=AE=E5=A4=8D=20JWT=20?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=20Token=20=E9=85=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #Comment comment #I1BMCY #Issue close https://gitee.com/LongbowEnterprise/dashboard/issues?id=I1BMCY --- src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj | 2 +- .../Controllers/Api/LoginController.cs | 13 +++++++++++-- .../Bootstrap.DataAccess.csproj | 2 +- .../Bootstrap.Client.DataAccess.csproj | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj b/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj index 922e0fbc..c60bd64e 100644 --- a/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj +++ b/src/admin/Bootstrap.Admin/Bootstrap.Admin.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/admin/Bootstrap.Admin/Controllers/Api/LoginController.cs b/src/admin/Bootstrap.Admin/Controllers/Api/LoginController.cs index f196215e..fca3795e 100644 --- a/src/admin/Bootstrap.Admin/Controllers/Api/LoginController.cs +++ b/src/admin/Bootstrap.Admin/Controllers/Api/LoginController.cs @@ -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 /// /// JWT 登陆认证接口 /// + /// /// /// [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; diff --git a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj index 59ff7c1a..d0873eee 100644 --- a/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj +++ b/src/admin/Bootstrap.DataAccess/Bootstrap.DataAccess.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj b/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj index df42d954..35c49cf0 100644 --- a/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj +++ b/src/client/Bootstrap.Client.DataAccess/Bootstrap.Client.DataAccess.csproj @@ -6,7 +6,7 @@ - +