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