0
我想在MongoDB上實現PersistedGrantStore,我已經成功地使用mongodb來存儲用戶和客戶端,現在我試圖存儲撥款而不是在內存授權商店中使用 I創建從IPersistedGrantStore我如何在我的MongoDB數據庫上實現PersistedGrantStore
繼承public class PersistedGrantStore : IPersistedGrantStore
{
public async Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
return await persistedGrantService.GetAllPersistedGrant(subjectId);
}
public async Task<PersistedGrant> GetAsync(string key)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
return await persistedGrantService.GetPersistedGrantByKey(key);
}
public async Task RemoveAllAsync(string subjectId, string clientId)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.RemoveAllBySubjectIdAndClientId(subjectId, clientId);
}
public async Task RemoveAllAsync(string subjectId, string clientId, string type)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.RemoveAllBySubjectIdAndClientIdAndType(subjectId, clientId, type);
}
public async Task RemoveAsync(string key)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.RemoveAllByKey(key);
}
public async Task StoreAsync(PersistedGrant grant)
{
PersistedGrantService persistedGrantService = new PersistedGrantService();
await persistedGrantService.InsertPersistedGrant(grant);
}
}
而且在startup.cs
public void ConfigureServices(IServiceCollection services)
{
var builder = services.AddIdentityServer()
.AddSigningCredential(cert)
.AddInMemoryIdentityResources(IdentityConfiguration.GetIdentityResources())
.AddInMemoryApiResources(ApiResourceConfiguration.GetApiResources());
builder.Services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
builder.Services.AddTransient<IProfileService, ProfileService>();
builder.Services.AddTransient<IClientStore, ClientStore>();
builder.Services.AddTransient<IPersistedGrantStore, PersistedGrantStore>();
}
看來不管我做什麼都不在PersistedGrantStore功能被稱爲類,我不知道我缺少這裏, STIL l我可以ping服務器並獲取訪問令牌,所以我假設內存存儲仍在使用中。