mirror of https://github.com/abpframework/abp.git
14 changed files with 474 additions and 67 deletions
@ -1,12 +0,0 @@ |
|||||
using Volo.Abp.Data; |
|
||||
using Volo.Abp.MongoDB; |
|
||||
|
|
||||
namespace Volo.Abp.OpenIddict.MongoDB; |
|
||||
|
|
||||
[ConnectionStringName(OpenIddictDbProperties.ConnectionStringName)] |
|
||||
public interface IOpenIddictMongoDbContext : IAbpMongoDbContext |
|
||||
{ |
|
||||
/* Define mongo collections here. Example: |
|
||||
* IMongoCollection<Question> Questions { get; } |
|
||||
*/ |
|
||||
} |
|
||||
@ -1,19 +0,0 @@ |
|||||
using Volo.Abp.Data; |
|
||||
using Volo.Abp.MongoDB; |
|
||||
|
|
||||
namespace Volo.Abp.OpenIddict.MongoDB; |
|
||||
|
|
||||
[ConnectionStringName(OpenIddictDbProperties.ConnectionStringName)] |
|
||||
public class OpenIddictMongoDbContext : AbpMongoDbContext, IOpenIddictMongoDbContext |
|
||||
{ |
|
||||
/* Add mongo collections here. Example: |
|
||||
* public IMongoCollection<Question> Questions => Collection<Question>(); |
|
||||
*/ |
|
||||
|
|
||||
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
|
||||
{ |
|
||||
base.CreateModel(modelBuilder); |
|
||||
|
|
||||
modelBuilder.ConfigureOpenIddict(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,13 +0,0 @@ |
|||||
using Volo.Abp; |
|
||||
using Volo.Abp.MongoDB; |
|
||||
|
|
||||
namespace Volo.Abp.OpenIddict.MongoDB; |
|
||||
|
|
||||
public static class OpenIddictMongoDbContextExtensions |
|
||||
{ |
|
||||
public static void ConfigureOpenIddict( |
|
||||
this IMongoModelBuilder builder) |
|
||||
{ |
|
||||
Check.NotNull(builder, nameof(builder)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,22 +0,0 @@ |
|||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Volo.Abp.Modularity; |
|
||||
using Volo.Abp.MongoDB; |
|
||||
|
|
||||
namespace Volo.Abp.OpenIddict.MongoDB; |
|
||||
|
|
||||
[DependsOn( |
|
||||
typeof(OpenIddictDomainModule), |
|
||||
typeof(AbpMongoDbModule) |
|
||||
)] |
|
||||
public class OpenIddictMongoDbModule : AbpModule |
|
||||
{ |
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
context.Services.AddMongoDbContext<OpenIddictMongoDbContext>(options => |
|
||||
{ |
|
||||
/* Add custom repositories here. Example: |
|
||||
* options.AddRepository<Question, MongoQuestionRepository>(); |
|
||||
*/ |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,27 @@ |
|||||
|
using System.Linq; |
||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict; |
||||
|
|
||||
|
internal static class AbpOpenIddictQueryableExtensions |
||||
|
{ |
||||
|
public static TQueryable SkipIf<T, TQueryable>([NotNull] this TQueryable query, bool condition, int count) |
||||
|
where TQueryable : IQueryable<T> |
||||
|
{ |
||||
|
Check.NotNull(query, nameof(query)); |
||||
|
|
||||
|
return condition |
||||
|
? (TQueryable)query.Skip(count) |
||||
|
: query; |
||||
|
} |
||||
|
|
||||
|
public static TQueryable TakeIf<T, TQueryable>([NotNull] this TQueryable query, bool condition, int count) |
||||
|
where TQueryable : IQueryable<T> |
||||
|
{ |
||||
|
Check.NotNull(query, nameof(query)); |
||||
|
|
||||
|
return condition |
||||
|
? (TQueryable)query.Take(count) |
||||
|
: query; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,62 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.Applications; |
||||
|
|
||||
|
public class MongoOpenIddictApplicationRepository : MongoDbRepository<OpenIddictMongoDbContext, OpenIddictApplication, Guid>, IOpenIddictApplicationRepository |
||||
|
{ |
||||
|
public MongoOpenIddictApplicationRepository(IMongoDbContextProvider<OpenIddictMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.As<IMongoQueryable<OpenIddictApplication>>() |
||||
|
.LongCountAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.FirstOrDefaultAsync(x => x.ClientId == clientId, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.RedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.OrderBy(x => x.Id) |
||||
|
.SkipIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(offset.HasValue, offset.Value) |
||||
|
.TakeIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(count.HasValue, count.Value) |
||||
|
.As<IMongoQueryable<OpenIddictApplication>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,90 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using OpenIddict.Abstractions; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.Authorizations; |
||||
|
|
||||
|
public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddictMongoDbContext, OpenIddictAuthorization, Guid>, IOpenIddictAuthorizationRepository |
||||
|
{ |
||||
|
public MongoOpenIddictAuthorizationRepository(IMongoDbContextProvider<OpenIddictMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken)).As<IMongoQueryable<OpenIddictAuthorization>>().LongCountAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.Where(x => x.Subject == subject && x.ApplicationId == client) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.Where(x => x.Subject == subject && x.Status == status && x.ApplicationId == client) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.Where(x => x.Subject == subject && x.Status == status && x.Type == type && x.ApplicationId == client) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.ApplicationId == applicationId).ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<OpenIddictAuthorization> FindByIdAsync(Guid id, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.OrderBy(authorization => authorization.Id!) |
||||
|
.SkipIf<OpenIddictAuthorization, IQueryable<OpenIddictAuthorization>>(offset.HasValue, offset.Value) |
||||
|
.TakeIf<OpenIddictAuthorization, IQueryable<OpenIddictAuthorization>>(count.HasValue, count.Value) |
||||
|
.As<IMongoQueryable<OpenIddictAuthorization>>().ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(cancellationToken); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
||||
|
.Where(x => x.CreationDate < date) |
||||
|
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !x.Tokens.Any())) |
||||
|
.OrderBy(x => x.Id) |
||||
|
.Take(count) |
||||
|
.ToListAsync(cancellationToken); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.Applications; |
||||
|
using Volo.Abp.OpenIddict.Authorizations; |
||||
|
using Volo.Abp.OpenIddict.Scopes; |
||||
|
using Volo.Abp.OpenIddict.Tokens; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
[ConnectionStringName(OpenIddictDbProperties.ConnectionStringName)] |
||||
|
public interface IOpenIddictMongoDbContext : IAbpMongoDbContext |
||||
|
{ |
||||
|
IMongoCollection<OpenIddictApplication> Applications { get; } |
||||
|
|
||||
|
IMongoCollection<OpenIddictAuthorization> Authorizations { get; } |
||||
|
|
||||
|
IMongoCollection<OpenIddictScope> Scopes { get; } |
||||
|
|
||||
|
IMongoCollection<OpenIddictToken> Tokens { get; } |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.Applications; |
||||
|
using Volo.Abp.OpenIddict.Authorizations; |
||||
|
using Volo.Abp.OpenIddict.Scopes; |
||||
|
using Volo.Abp.OpenIddict.Tokens; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
[ConnectionStringName(OpenIddictDbProperties.ConnectionStringName)] |
||||
|
public class OpenIddictMongoDbContext : AbpMongoDbContext, IOpenIddictMongoDbContext |
||||
|
{ |
||||
|
public IMongoCollection<OpenIddictApplication> Applications => Collection<OpenIddictApplication>(); |
||||
|
|
||||
|
public IMongoCollection<OpenIddictAuthorization> Authorizations => Collection<OpenIddictAuthorization>(); |
||||
|
|
||||
|
public IMongoCollection<OpenIddictScope> Scopes => Collection<OpenIddictScope>(); |
||||
|
|
||||
|
public IMongoCollection<OpenIddictToken> Tokens => Collection<OpenIddictToken>(); |
||||
|
|
||||
|
protected override void CreateModel(IMongoModelBuilder modelBuilder) |
||||
|
{ |
||||
|
base.CreateModel(modelBuilder); |
||||
|
|
||||
|
modelBuilder.ConfigureOpenIddict(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.Applications; |
||||
|
using Volo.Abp.OpenIddict.Authorizations; |
||||
|
using Volo.Abp.OpenIddict.Scopes; |
||||
|
using Volo.Abp.OpenIddict.Tokens; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
public static class OpenIddictMongoDbContextExtensions |
||||
|
{ |
||||
|
public static void ConfigureOpenIddict( |
||||
|
this IMongoModelBuilder builder) |
||||
|
{ |
||||
|
Check.NotNull(builder, nameof(builder)); |
||||
|
|
||||
|
builder.Entity<OpenIddictApplication>(b => |
||||
|
{ |
||||
|
b.CollectionName = OpenIddictDbProperties.DbTablePrefix + "Applications"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<OpenIddictAuthorization>(b => |
||||
|
{ |
||||
|
b.CollectionName = OpenIddictDbProperties.DbTablePrefix + "Authorizations"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<OpenIddictScope>(b => |
||||
|
{ |
||||
|
b.CollectionName = OpenIddictDbProperties.DbTablePrefix + "Scopes"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<OpenIddictToken>(b => |
||||
|
{ |
||||
|
b.CollectionName = OpenIddictDbProperties.DbTablePrefix + "Tokens"; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.Applications; |
||||
|
using Volo.Abp.OpenIddict.Authorizations; |
||||
|
using Volo.Abp.OpenIddict.Scopes; |
||||
|
using Volo.Abp.OpenIddict.Tokens; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(OpenIddictDomainModule), |
||||
|
typeof(AbpMongoDbModule) |
||||
|
)] |
||||
|
public class OpenIddictMongoDbModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
context.Services.AddMongoDbContext<OpenIddictMongoDbContext>(options => |
||||
|
{ |
||||
|
options.AddDefaultRepositories<IOpenIddictMongoDbContext>(); |
||||
|
|
||||
|
options.AddRepository<OpenIddictApplication, MongoOpenIddictApplicationRepository>(); |
||||
|
options.AddRepository<OpenIddictAuthorization, MongoOpenIddictAuthorizationRepository>(); |
||||
|
options.AddRepository<OpenIddictScope, MongoOpenIddictScopeRepository>(); |
||||
|
options.AddRepository<OpenIddictToken, MongoOpenIddictTokenRepository>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.Scopes; |
||||
|
|
||||
|
public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoDbContext, OpenIddictScope, Guid>, IOpenIddictScopeRepository |
||||
|
{ |
||||
|
public MongoOpenIddictScopeRepository(IMongoDbContextProvider<OpenIddictMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken)).As<IMongoQueryable<OpenIddictScope>>().LongCountAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Name == name, cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => names.Contains(x.Name)) |
||||
|
.As<IMongoQueryable<OpenIddictScope>>() |
||||
|
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Resources.Contains(resource)) |
||||
|
.As<IMongoQueryable<OpenIddictScope>>() |
||||
|
.ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.OrderBy((await GetMongoQueryableAsync(cancellationToken)), x => x.Id) |
||||
|
.SkipIf<OpenIddictScope, IQueryable<OpenIddictScope>>(offset.HasValue, offset.Value) |
||||
|
.TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count.Value) |
||||
|
.As<IMongoQueryable<OpenIddictScope>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,113 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using OpenIddict.Abstractions; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.OpenIddict.Authorizations; |
||||
|
using Volo.Abp.OpenIddict.MongoDB; |
||||
|
|
||||
|
namespace Volo.Abp.OpenIddict.Tokens; |
||||
|
|
||||
|
public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoDbContext, OpenIddictToken, Guid>, IOpenIddictTokenRepository |
||||
|
{ |
||||
|
public MongoOpenIddictTokenRepository(IMongoDbContextProvider<OpenIddictMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).LongCountAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client && x.Status == status) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client && x.Status == status && x.Type == type) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.ApplicationId == applicationId) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.AuthorizationId == authorizationId) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<OpenIddictToken> FindByIdAsync(Guid id, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await Queryable.OrderBy((await GetMongoQueryableAsync(cancellationToken)), x => x.Id) |
||||
|
.SkipIf<OpenIddictToken, IQueryable<OpenIddictToken>>(offset.HasValue, offset.Value) |
||||
|
.TakeIf<OpenIddictToken, IQueryable<OpenIddictToken>>(count.HasValue, count.Value) |
||||
|
.As<IMongoQueryable<OpenIddictToken>>() |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
//TODO: Test & Improve?
|
||||
|
return await (from token in await GetMongoQueryableAsync(cancellationToken) |
||||
|
join authorization in (await GetMongoQueryableAsync<OpenIddictAuthorization>(cancellationToken)) |
||||
|
on token.AuthorizationId equals authorization.Id into ta |
||||
|
from a in ta |
||||
|
where token.CreationDate < date |
||||
|
where (token.Status != OpenIddictConstants.Statuses.Inactive && |
||||
|
token.Status != OpenIddictConstants.Statuses.Valid) || |
||||
|
(a != null && a.Status != OpenIddictConstants.Statuses.Valid) || |
||||
|
token.ExpirationDate < DateTime.UtcNow |
||||
|
orderby token.Id |
||||
|
select token).Take(count).ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue