using System;
using System.Text.Json;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Distributed;
using YYApi.Communications;
namespace YYApi.Helpers
{
///
/// 认证助手
///
public class YYAuth
{
private IDistributedCache Cache { get; }
public YYAuth(IDistributedCache cache)
{
Cache = cache;
}
///
/// 产生一个Token记录并返回Token
///
///
///
public string Set(int id, string type = "user")
{
var uuid = Guid.NewGuid().ToString();
var loginItem = new YYLoginItem
{
Id = id,
Type = type
};
Cache.SetString(uuid, JsonSerializer.Serialize(loginItem));
return uuid;
}
}
}