C#公共类
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
729 B

using System;
using System.Linq;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Mvc;
namespace Common.Helper.Auth
{
public static class JwtHelper
{
/// <summary>
/// 获取当前jwt缓存里面的数值 直接本地this.CurValue即可
/// </summary>
/// <param name="controller"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string CurValue(this ControllerBase controller,string key)
{
var auth = controller.HttpContext.AuthenticateAsync().Result.Principal.Claims;
var value = auth.FirstOrDefault(t => t.Type.Equals(key))?.Value;
return value;
}
}
}