我是IdentityServer4的新手。我读到我需要实现一个IPersistedGrantStore将刷新令牌存储到PersistedGrants数据库中的表中。
当本机应用程序请求新的访问令牌时,IdentityServer日志如下:"refresh_token" grant with value: "{value}" not found in store。
那是因为我正在使用持久授权存储的内存版本。因此,我需要在PersistedGrant表中存储刷新令牌。
因此,在我的startup.cs中,添加了以下行:
builder.Services.AddScoped<IPersistedGrantStore, PersistedGrantStore>();
Run Code Online (Sandbox Code Playgroud)
和IPersistedGrantStore.cs是
public interface IPersistedGrantStore
{
Task StoreAsync(CustomPersistedGrant grant);
Task<CustomPersistedGrant> GetAsync(string key);
Task<IEnumerable<CustomPersistedGrant>> GetAllAsync(string subjectId);
}
Run Code Online (Sandbox Code Playgroud)
所以我有一个CustomPersistedGrant.cs类
public class CustomPersistedGrant
{
public string Key { get; set; }
public string Type { get; set; }
public string SubjectId { get; set; }
public string ClientId { get; set; }
public DateTime CreationTime { …Run Code Online (Sandbox Code Playgroud) 我需要使用 Serilog.Exceptions 包来捕获异常。Serilog 是从 appsettings.json 读取的
{
"Serilog": {
"Using": [
"Serilog.Sinks.RollingFile",
"Serilog.Sinks.Seq"
],
"WriteTo": [
{
"Name": "RollingFile",
"Args": {
"restrictedToMinimumLevel": "Debug",
"pathFormat": "myPath\\log-{Date}.log"
}
},
{
"Name": "RollingFile",
"Args": {
"restrictedToMinimumLevel": "Error",
"pathFormat": "myPath\\error-{Date}.log"
}
},
{
"Name": "Seq",
"Args": {
"serverUrl": "myUrl",
"apiKey": "myApiKey"
}
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithThreadId"
],
"Properties": {
"Application": "myApplicationName"
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的startup.cs中
var logger = new LoggerConfiguration()
.Enrich.WithExceptionDetails()
.ReadFrom.Configuration(Configuration)
.CreateLogger();
Log.Logger = logger;
Run Code Online (Sandbox Code Playgroud)
但这不起作用。我是否需要在 Serilog.Exceptions 包的 appsettings.json …
我在mongo db doc中读到,我也可以使用LINQ,但我对此一无所知。
例如,如果我写:
var result = collection.Find(filter);
Run Code Online (Sandbox Code Playgroud)
和
var result = collection.AsQueryable()
.Where(x => x.Foo == 114)
Run Code Online (Sandbox Code Playgroud)
什么是更好的?
LINQ筛选器基于整个集合吗?在获得整个收藏之前,它会进行过滤吗?还是在过滤器之前,它给了我已经过滤的集合?