增加登录过期时间支持
This commit is contained in:
parent
956e3349fe
commit
785457a5f4
|
@ -1,10 +1,12 @@
|
||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.AspNetCore.Authentication;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using SqlSugar;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace Falcon.SugarApi.FalconClaim
|
namespace Falcon.SugarApi.FalconClaim
|
||||||
{
|
{
|
||||||
|
@ -51,7 +53,8 @@ namespace Falcon.SugarApi.FalconClaim
|
||||||
return UnLoginResultTask;
|
return UnLoginResultTask;
|
||||||
}
|
}
|
||||||
return Task.FromResult(AuthenticateResult.Success(ticket));
|
return Task.FromResult(AuthenticateResult.Success(ticket));
|
||||||
} catch(Exception) {
|
}
|
||||||
|
catch (Exception) {
|
||||||
return UnLoginResultTask;
|
return UnLoginResultTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,12 +85,18 @@ namespace Falcon.SugarApi.FalconClaim
|
||||||
List<Claim>? claims = null;
|
List<Claim>? claims = null;
|
||||||
try {
|
try {
|
||||||
claims = this.TokenBuilter.GetClaims(token);
|
claims = this.TokenBuilter.GetClaims(token);
|
||||||
} catch(Exception) {
|
}
|
||||||
|
catch (Exception) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (claims == null || claims.Count == 0) {
|
if (claims == null || claims.Count == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
//检测是否设置过期时间
|
||||||
|
var dtExp = claims.Where(m => m.Type == ClaimTypes.Expiration);
|
||||||
|
if (dtExp.Any() && !DateTime.TryParse(dtExp.First().Value, out var et) && et > DateTime.Now) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var cid = new ClaimsIdentity(FalconClaimOption.SchemeName);
|
var cid = new ClaimsIdentity(FalconClaimOption.SchemeName);
|
||||||
cid.AddClaims(claims);
|
cid.AddClaims(claims);
|
||||||
var principal = new ClaimsPrincipal(cid);
|
var principal = new ClaimsPrincipal(cid);
|
||||||
|
|
|
@ -14,5 +14,9 @@
|
||||||
/// 密码
|
/// 密码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Password { get; set; }
|
public string? Password { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// 过期小时数。0或者空为不限制
|
||||||
|
/// </summary>
|
||||||
|
public int? ExpHours { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user