mirror of https://github.com/abpframework/abp.git
3 changed files with 137 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.Grants |
||||
|
{ |
||||
|
public interface IPersistentGrantRepository : IRepository<PersistedGrant> |
||||
|
{ |
||||
|
Task<PersistedGrant> FindByKeyAsync(string key); |
||||
|
|
||||
|
Task<List<PersistedGrant>> GetListBySubjectIdAsync(string key); |
||||
|
|
||||
|
Task DeleteAsync(string subjectId, string clientId); |
||||
|
|
||||
|
Task DeleteAsync(string subjectId, string clientId, string type); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,70 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Dynamic.Core; |
||||
|
using System.Threading.Tasks; |
||||
|
using IdentityServer4.Stores; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.ObjectMapping; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer.Grants |
||||
|
{ |
||||
|
public class PersistedGrantStore : IPersistedGrantStore, ITransientDependency |
||||
|
{ |
||||
|
private readonly IPersistentGrantRepository _persistentGrantRepository; |
||||
|
private readonly IObjectMapper _objectMapper; |
||||
|
|
||||
|
public PersistedGrantStore(IPersistentGrantRepository persistentGrantRepository, IObjectMapper objectMapper) |
||||
|
{ |
||||
|
_persistentGrantRepository = persistentGrantRepository; |
||||
|
_objectMapper = objectMapper; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task StoreAsync(IdentityServer4.Models.PersistedGrant grant) |
||||
|
{ |
||||
|
var entity = _objectMapper.Map<IdentityServer4.Models.PersistedGrant, PersistedGrant>(grant); |
||||
|
var existing = _persistentGrantRepository.FindByKeyAsync(grant.Key); |
||||
|
if (existing == null) |
||||
|
{ |
||||
|
await _persistentGrantRepository.InsertAsync(entity); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
await _persistentGrantRepository.UpdateAsync(entity); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<IdentityServer4.Models.PersistedGrant> GetAsync(string key) |
||||
|
{ |
||||
|
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key); |
||||
|
return _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(persistedGrant); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<IEnumerable<IdentityServer4.Models.PersistedGrant>> GetAllAsync(string subjectId) |
||||
|
{ |
||||
|
var persistedGrants = await _persistentGrantRepository.GetListBySubjectIdAsync(subjectId); |
||||
|
return persistedGrants.Select(x => _objectMapper.Map<PersistedGrant, IdentityServer4.Models.PersistedGrant>(x)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task RemoveAsync(string key) |
||||
|
{ |
||||
|
var persistedGrant = await _persistentGrantRepository.FindByKeyAsync(key); |
||||
|
if (persistedGrant == null) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
await _persistentGrantRepository.DeleteAsync(persistedGrant); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task RemoveAllAsync(string subjectId, string clientId) |
||||
|
{ |
||||
|
await _persistentGrantRepository.DeleteAsync(subjectId, clientId); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task RemoveAllAsync(string subjectId, string clientId, string type) |
||||
|
{ |
||||
|
await _persistentGrantRepository.DeleteAsync(subjectId, clientId, type); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; |
||||
|
using Volo.Abp.EntityFrameworkCore; |
||||
|
using Volo.Abp.IdentityServer.EntityFrameworkCore; |
||||
|
using Volo.Abp.IdentityServer.Grants; |
||||
|
|
||||
|
namespace Volo.Abp.IdentityServer |
||||
|
{ |
||||
|
public class PersistentGrantRepository : EfCoreRepository<IdentityServerDbContext, PersistedGrant>, IPersistentGrantRepository |
||||
|
{ |
||||
|
public PersistentGrantRepository(IDbContextProvider<IdentityServerDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public Task<PersistedGrant> FindByKeyAsync(string key) |
||||
|
{ |
||||
|
return DbSet.FirstOrDefaultAsync(x => x.Key == key); |
||||
|
} |
||||
|
|
||||
|
public Task<List<PersistedGrant>> GetListBySubjectIdAsync(string subjectId) |
||||
|
{ |
||||
|
return DbSet.Where(x => x.SubjectId == subjectId).ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public Task DeleteAsync(string subjectId, string clientId) |
||||
|
{ |
||||
|
DbSet.RemoveRange( |
||||
|
DbSet.Where(x => x.SubjectId == subjectId && x.ClientId == clientId) |
||||
|
); |
||||
|
|
||||
|
return Task.FromResult(0); |
||||
|
} |
||||
|
|
||||
|
public Task DeleteAsync(string subjectId, string clientId, string type) |
||||
|
{ |
||||
|
DbSet.RemoveRange( |
||||
|
DbSet.Where(x => |
||||
|
x.SubjectId == subjectId && |
||||
|
x.ClientId == clientId && |
||||
|
x.Type == type) |
||||
|
); |
||||
|
|
||||
|
return Task.FromResult(0); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue