pull/12084/head
maliming 4 years ago
parent afa47aff6b
commit 15b9e4a4d9
No known key found for this signature in database
GPG Key ID: 096224957E51C89E

@ -172,6 +172,43 @@ https://documentation.openiddict.com
https://github.com/openiddict/openiddict-core#resources
### Token encryption
https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html
> By default, OpenIddict enforces encryption for all the token types it supports. While this enforcement cannot be disabled for authorization codes, refresh tokens and device codes for security reasons, it can be relaxed for access tokens when integration with third-party APIs/resource servers is desired. Access token encryption can also be disabled if the resource servers receiving the access tokens don't fully support JSON Web Encryption.
```cs
PreConfigure<OpenIddictServerBuilder>(builder =>
{
builder.DisableAccessTokenEncryption();
});
```
An example of using `SecurityKey`
> In production, it is recommended to use two RSA certificates, distinct from the certificate(s) used for HTTPS: one for encryption, one for signing.
```cs
// In OpenIddict Server
PreConfigure<OpenIddictServerBuilder>(builder =>
{
builder.AddSigningKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78")));
builder.AddEncryptionKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80")));
});
//In Client AddJwtBearer
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
//Other configuration
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78"));
options.TokenValidationParameters.TokenDecryptionKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80"));
});
```
### PKCE
https://documentation.openiddict.com/configuration/proof-key-for-code-exchange.html

@ -1,4 +1,10 @@
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
@ -16,6 +22,10 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
{
options.Authority = "https://localhost:44301";
options.Audience = "AbpAPIResource";
// See OpenIddictServerModule`s PreConfigureServices method.
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78"));
options.TokenValidationParameters.TokenDecryptionKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80"));
});
var app = builder.Build();
@ -34,4 +44,4 @@ app.UseAuthorization();
app.MapControllers();
app.Run();
app.Run();

@ -13,7 +13,7 @@ using Volo.Abp.EntityFrameworkCore;
namespace OpenIddict.Demo.Server.Migrations
{
[DbContext(typeof(ServerDbContext))]
[Migration("20220331065901_Initial")]
[Migration("20220405034203_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -757,7 +757,7 @@ namespace OpenIddict.Demo.Server.Migrations
.IsUnique()
.HasFilter("[ClientId] IS NOT NULL");
b.ToTable("AbpOpenIddictApplications", (string)null);
b.ToTable("OpenIddictApplications", (string)null);
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", b =>
@ -794,6 +794,10 @@ namespace OpenIddict.Demo.Server.Migrations
.HasColumnType("datetime2")
.HasColumnName("DeletionTime");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
@ -830,7 +834,7 @@ namespace OpenIddict.Demo.Server.Migrations
b.HasIndex("ApplicationId", "Status", "Subject", "Type");
b.ToTable("AbpOpenIddictAuthorizations", (string)null);
b.ToTable("OpenIddictAuthorizations", (string)null);
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Scopes.OpenIddictScope", b =>
@ -907,7 +911,7 @@ namespace OpenIddict.Demo.Server.Migrations
.IsUnique()
.HasFilter("[Name] IS NOT NULL");
b.ToTable("AbpOpenIddictScopes", (string)null);
b.ToTable("OpenIddictScopes", (string)null);
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Tokens.OpenIddictToken", b =>
@ -950,6 +954,10 @@ namespace OpenIddict.Demo.Server.Migrations
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("datetime2");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
@ -999,7 +1007,7 @@ namespace OpenIddict.Demo.Server.Migrations
b.HasIndex("ApplicationId", "Status", "Subject", "Type");
b.ToTable("AbpOpenIddictTokens", (string)null);
b.ToTable("OpenIddictTokens", (string)null);
});
modelBuilder.Entity("Volo.Abp.PermissionManagement.PermissionGrant", b =>
@ -1237,18 +1245,18 @@ namespace OpenIddict.Demo.Server.Migrations
modelBuilder.Entity("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", b =>
{
b.HasOne("Volo.Abp.OpenIddict.Applications.OpenIddictApplication", null)
.WithMany("Authorizations")
.WithMany()
.HasForeignKey("ApplicationId");
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Tokens.OpenIddictToken", b =>
{
b.HasOne("Volo.Abp.OpenIddict.Applications.OpenIddictApplication", null)
.WithMany("Tokens")
.WithMany()
.HasForeignKey("ApplicationId");
b.HasOne("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", null)
.WithMany("Tokens")
.WithMany()
.HasForeignKey("AuthorizationId");
});
@ -1284,18 +1292,6 @@ namespace OpenIddict.Demo.Server.Migrations
b.Navigation("Roles");
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Applications.OpenIddictApplication", b =>
{
b.Navigation("Authorizations");
b.Navigation("Tokens");
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", b =>
{
b.Navigation("Tokens");
});
modelBuilder.Entity("Volo.Abp.TenantManagement.Tenant", b =>
{
b.Navigation("ConnectionStrings");

@ -59,64 +59,6 @@ namespace OpenIddict.Demo.Server.Migrations
table.PrimaryKey("PK_AbpLinkUsers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AbpOpenIddictApplications",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ClientId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
ClientSecret = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConsentType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
DisplayNames = table.Column<string>(type: "nvarchar(max)", nullable: true),
Permissions = table.Column<string>(type: "nvarchar(max)", nullable: true),
PostLogoutRedirectUris = table.Column<string>(type: "nvarchar(max)", nullable: true),
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true),
RedirectUris = table.Column<string>(type: "nvarchar(max)", nullable: true),
Requirements = table.Column<string>(type: "nvarchar(max)", nullable: true),
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AbpOpenIddictApplications", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AbpOpenIddictScopes",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Descriptions = table.Column<string>(type: "nvarchar(max)", nullable: true),
DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
DisplayNames = table.Column<string>(type: "nvarchar(max)", nullable: true),
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true),
Resources = table.Column<string>(type: "nvarchar(max)", nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AbpOpenIddictScopes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AbpOrganizationUnits",
columns: table => new
@ -280,18 +222,23 @@ namespace OpenIddict.Demo.Server.Migrations
});
migrationBuilder.CreateTable(
name: "AbpOpenIddictAuthorizations",
name: "OpenIddictApplications",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
ApplicationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: true),
ClientId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true),
ClientSecret = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConsentType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
DisplayNames = table.Column<string>(type: "nvarchar(max)", nullable: true),
Permissions = table.Column<string>(type: "nvarchar(max)", nullable: true),
PostLogoutRedirectUris = table.Column<string>(type: "nvarchar(max)", nullable: true),
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true),
Scopes = table.Column<string>(type: "nvarchar(max)", nullable: true),
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
Subject = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: true),
RedirectUris = table.Column<string>(type: "nvarchar(max)", nullable: true),
Requirements = table.Column<string>(type: "nvarchar(max)", nullable: true),
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
@ -302,12 +249,34 @@ namespace OpenIddict.Demo.Server.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_AbpOpenIddictAuthorizations", x => x.Id);
table.ForeignKey(
name: "FK_AbpOpenIddictAuthorizations_AbpOpenIddictApplications_ApplicationId",
column: x => x.ApplicationId,
principalTable: "AbpOpenIddictApplications",
principalColumn: "Id");
table.PrimaryKey("PK_OpenIddictApplications", x => x.Id);
});
migrationBuilder.CreateTable(
name: "OpenIddictScopes",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: true),
Descriptions = table.Column<string>(type: "nvarchar(max)", nullable: true),
DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
DisplayNames = table.Column<string>(type: "nvarchar(max)", nullable: true),
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true),
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true),
Resources = table.Column<string>(type: "nvarchar(max)", nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OpenIddictScopes", x => x.Id);
});
migrationBuilder.CreateTable(
@ -493,11 +462,42 @@ namespace OpenIddict.Demo.Server.Migrations
});
migrationBuilder.CreateTable(
name: "AbpOpenIddictTokens",
name: "OpenIddictAuthorizations",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ApplicationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: true),
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true),
Scopes = table.Column<string>(type: "nvarchar(max)", nullable: true),
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
Subject = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: true),
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OpenIddictAuthorizations", x => x.Id);
table.ForeignKey(
name: "FK_OpenIddictAuthorizations_OpenIddictApplications_ApplicationId",
column: x => x.ApplicationId,
principalTable: "OpenIddictApplications",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "OpenIddictTokens",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
ApplicationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
AuthorizationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: true),
@ -509,6 +509,8 @@ namespace OpenIddict.Demo.Server.Migrations
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
Subject = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: true),
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
@ -519,16 +521,16 @@ namespace OpenIddict.Demo.Server.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_AbpOpenIddictTokens", x => x.Id);
table.PrimaryKey("PK_OpenIddictTokens", x => x.Id);
table.ForeignKey(
name: "FK_AbpOpenIddictTokens_AbpOpenIddictApplications_ApplicationId",
name: "FK_OpenIddictTokens_OpenIddictApplications_ApplicationId",
column: x => x.ApplicationId,
principalTable: "AbpOpenIddictApplications",
principalTable: "OpenIddictApplications",
principalColumn: "Id");
table.ForeignKey(
name: "FK_AbpOpenIddictTokens_AbpOpenIddictAuthorizations_AuthorizationId",
name: "FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId",
column: x => x.AuthorizationId,
principalTable: "AbpOpenIddictAuthorizations",
principalTable: "OpenIddictAuthorizations",
principalColumn: "Id");
});
@ -546,42 +548,6 @@ namespace OpenIddict.Demo.Server.Migrations
unique: true,
filter: "[SourceTenantId] IS NOT NULL AND [TargetTenantId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_AbpOpenIddictApplications_ClientId",
table: "AbpOpenIddictApplications",
column: "ClientId",
unique: true,
filter: "[ClientId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_AbpOpenIddictAuthorizations_ApplicationId_Status_Subject_Type",
table: "AbpOpenIddictAuthorizations",
columns: new[] { "ApplicationId", "Status", "Subject", "Type" });
migrationBuilder.CreateIndex(
name: "IX_AbpOpenIddictScopes_Name",
table: "AbpOpenIddictScopes",
column: "Name",
unique: true,
filter: "[Name] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_AbpOpenIddictTokens_ApplicationId_Status_Subject_Type",
table: "AbpOpenIddictTokens",
columns: new[] { "ApplicationId", "Status", "Subject", "Type" });
migrationBuilder.CreateIndex(
name: "IX_AbpOpenIddictTokens_AuthorizationId",
table: "AbpOpenIddictTokens",
column: "AuthorizationId");
migrationBuilder.CreateIndex(
name: "IX_AbpOpenIddictTokens_ReferenceId",
table: "AbpOpenIddictTokens",
column: "ReferenceId",
unique: true,
filter: "[ReferenceId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_AbpOrganizationUnitRoles_RoleId_OrganizationUnitId",
table: "AbpOrganizationUnitRoles",
@ -685,6 +651,42 @@ namespace OpenIddict.Demo.Server.Migrations
name: "IX_AbpUsers_UserName",
table: "AbpUsers",
column: "UserName");
migrationBuilder.CreateIndex(
name: "IX_OpenIddictApplications_ClientId",
table: "OpenIddictApplications",
column: "ClientId",
unique: true,
filter: "[ClientId] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_OpenIddictAuthorizations_ApplicationId_Status_Subject_Type",
table: "OpenIddictAuthorizations",
columns: new[] { "ApplicationId", "Status", "Subject", "Type" });
migrationBuilder.CreateIndex(
name: "IX_OpenIddictScopes_Name",
table: "OpenIddictScopes",
column: "Name",
unique: true,
filter: "[Name] IS NOT NULL");
migrationBuilder.CreateIndex(
name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type",
table: "OpenIddictTokens",
columns: new[] { "ApplicationId", "Status", "Subject", "Type" });
migrationBuilder.CreateIndex(
name: "IX_OpenIddictTokens_AuthorizationId",
table: "OpenIddictTokens",
column: "AuthorizationId");
migrationBuilder.CreateIndex(
name: "IX_OpenIddictTokens_ReferenceId",
table: "OpenIddictTokens",
column: "ReferenceId",
unique: true,
filter: "[ReferenceId] IS NOT NULL");
}
protected override void Down(MigrationBuilder migrationBuilder)
@ -698,12 +700,6 @@ namespace OpenIddict.Demo.Server.Migrations
migrationBuilder.DropTable(
name: "AbpLinkUsers");
migrationBuilder.DropTable(
name: "AbpOpenIddictScopes");
migrationBuilder.DropTable(
name: "AbpOpenIddictTokens");
migrationBuilder.DropTable(
name: "AbpOrganizationUnitRoles");
@ -738,7 +734,10 @@ namespace OpenIddict.Demo.Server.Migrations
name: "AbpUserTokens");
migrationBuilder.DropTable(
name: "AbpOpenIddictAuthorizations");
name: "OpenIddictScopes");
migrationBuilder.DropTable(
name: "OpenIddictTokens");
migrationBuilder.DropTable(
name: "AbpTenants");
@ -753,7 +752,10 @@ namespace OpenIddict.Demo.Server.Migrations
name: "AbpUsers");
migrationBuilder.DropTable(
name: "AbpOpenIddictApplications");
name: "OpenIddictAuthorizations");
migrationBuilder.DropTable(
name: "OpenIddictApplications");
}
}
}

@ -755,7 +755,7 @@ namespace OpenIddict.Demo.Server.Migrations
.IsUnique()
.HasFilter("[ClientId] IS NOT NULL");
b.ToTable("AbpOpenIddictApplications", (string)null);
b.ToTable("OpenIddictApplications", (string)null);
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", b =>
@ -792,6 +792,10 @@ namespace OpenIddict.Demo.Server.Migrations
.HasColumnType("datetime2")
.HasColumnName("DeletionTime");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
@ -828,7 +832,7 @@ namespace OpenIddict.Demo.Server.Migrations
b.HasIndex("ApplicationId", "Status", "Subject", "Type");
b.ToTable("AbpOpenIddictAuthorizations", (string)null);
b.ToTable("OpenIddictAuthorizations", (string)null);
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Scopes.OpenIddictScope", b =>
@ -905,7 +909,7 @@ namespace OpenIddict.Demo.Server.Migrations
.IsUnique()
.HasFilter("[Name] IS NOT NULL");
b.ToTable("AbpOpenIddictScopes", (string)null);
b.ToTable("OpenIddictScopes", (string)null);
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Tokens.OpenIddictToken", b =>
@ -948,6 +952,10 @@ namespace OpenIddict.Demo.Server.Migrations
b.Property<DateTime?>("ExpirationDate")
.HasColumnType("datetime2");
b.Property<string>("ExtraProperties")
.HasColumnType("nvarchar(max)")
.HasColumnName("ExtraProperties");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
@ -997,7 +1005,7 @@ namespace OpenIddict.Demo.Server.Migrations
b.HasIndex("ApplicationId", "Status", "Subject", "Type");
b.ToTable("AbpOpenIddictTokens", (string)null);
b.ToTable("OpenIddictTokens", (string)null);
});
modelBuilder.Entity("Volo.Abp.PermissionManagement.PermissionGrant", b =>
@ -1235,18 +1243,18 @@ namespace OpenIddict.Demo.Server.Migrations
modelBuilder.Entity("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", b =>
{
b.HasOne("Volo.Abp.OpenIddict.Applications.OpenIddictApplication", null)
.WithMany("Authorizations")
.WithMany()
.HasForeignKey("ApplicationId");
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Tokens.OpenIddictToken", b =>
{
b.HasOne("Volo.Abp.OpenIddict.Applications.OpenIddictApplication", null)
.WithMany("Tokens")
.WithMany()
.HasForeignKey("ApplicationId");
b.HasOne("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", null)
.WithMany("Tokens")
.WithMany()
.HasForeignKey("AuthorizationId");
});
@ -1282,18 +1290,6 @@ namespace OpenIddict.Demo.Server.Migrations
b.Navigation("Roles");
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Applications.OpenIddictApplication", b =>
{
b.Navigation("Authorizations");
b.Navigation("Tokens");
});
modelBuilder.Entity("Volo.Abp.OpenIddict.Authorizations.OpenIddictAuthorization", b =>
{
b.Navigation("Tokens");
});
modelBuilder.Entity("Volo.Abp.TenantManagement.Tenant", b =>
{
b.Navigation("ConnectionStrings");

@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>OpenIddict.Demo.Server1</AssemblyName>
</PropertyGroup>
<ItemGroup>

@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Authentication;
using System.Text;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Abstractions;
using OpenIddict.Demo.Server.EntityFrameworkCore;
using Volo.Abp;
@ -75,8 +77,24 @@ namespace OpenIddict.Demo.Server;
)]
public class OpenIddictServerModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<OpenIddictServerBuilder>(builder =>
{
//https://documentation.openiddict.com/configuration/token-formats.html#disabling-jwt-access-token-encryption
//https://documentation.openiddict.com/configuration/encryption-and-signing-credentials.html
builder.AddSigningKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78")));
builder.AddEncryptionKey(new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80")));
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpOpenIddictOptions>(options =>
{
options.AddDevelopmentEncryptionAndSigningCertificate = false;
});
context.Services.AddAbpDbContext<ServerDbContext>(options =>
{
options.AddDefaultRepositories(includeAllEntities: true);

@ -1,3 +1,5 @@
using System.Text;
using Microsoft.IdentityModel.Tokens;
using OpenIddict.Demo.Server;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Localization;
@ -35,6 +37,10 @@ builder.Services.AddAuthentication()
options.Audience = "AbpAPIResource";
options.MapInboundClaims = false;
// See OpenIddictServerModule`s PreConfigureServices method.
options.TokenValidationParameters.IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_C40DBB176E78"));
options.TokenValidationParameters.TokenDecryptionKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("Abp_OpenIddict_Demo_87E33FC57D80"));
});
await builder.AddApplicationAsync<OpenIddictServerModule>();

@ -3,7 +3,7 @@ using JetBrains.Annotations;
namespace Volo.Abp.OpenIddict;
internal static class AbpOpenIddictQueryableExtensions
public static class AbpOpenIddictQueryableExtensions
{
public static TQueryable SkipIf<T, TQueryable>([NotNull] this TQueryable query, bool condition, int count)
where TQueryable : IQueryable<T>

@ -2,9 +2,9 @@
public static class AbpOpenIddictDbProperties
{
public static string DbTablePrefix { get; set; } = "AbpOpenIddict"; //TODO: Rename to "OpenIddict"
public static string DbTablePrefix { get; set; } = "OpenIddict";
public static string DbSchema { get; set; } = null;
public const string ConnectionStringName = "AbpOpenIddict"; //TODO: Rename to "OpenIddict"
public const string ConnectionStringName = "OpenIddict";
}

@ -70,13 +70,12 @@ public class AbpOpenIddictDomainModule : AbpModule
.SetDefaultScopeEntity<OpenIddictScope>()
.SetDefaultTokenEntity<OpenIddictToken>();
builder.DisableEntityCaching();
services.ExecutePreConfiguredActions(builder);
})
.AddServer(builder =>
{
// Access token encryption can only be disabled when using JWT tokens.
builder.DisableAccessTokenEncryption(); //TODO: Should we always disable this?
builder
.SetAuthorizationEndpointUris("/connect/authorize")
// /.well-known/oauth-authorization-server

@ -16,11 +16,6 @@ using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Applications;
//https://github.com/abpframework/abp/pull/12094
[ExposeServices(
typeof(IOpenIddictApplicationStore<OpenIddictApplication>),
typeof(AbpOpenIddictApplicationStore)
)]
public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictApplicationRepository>, IOpenIddictApplicationStore<OpenIddictApplication>, IScopedDependency
{
protected IOpenIddictTokenRepository TokenRepository { get; }
@ -60,16 +55,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.RepeatableRead))
{
if (application.Tokens.Any())
{
await TokenRepository.DeleteManyAsync(application.Tokens, cancellationToken: cancellationToken);
}
var tokens = application.Authorizations.SelectMany(x => x.Tokens).ToList();
if (tokens.Any())
{
await TokenRepository.DeleteManyAsync(tokens, cancellationToken: cancellationToken);
}
await TokenRepository.DeleteManyByApplicationIdAsync(application.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(application, cancellationToken: cancellationToken);
@ -81,21 +67,21 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
return await Repository.FindAsync(ConvertIdentifierFromString(identifier), cancellationToken: cancellationToken);
}
public async ValueTask<OpenIddictApplication> FindByClientIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByClientIdAsync(identifier, includeDetails: true, cancellationToken: cancellationToken);
return await Repository.FindByClientIdAsync(identifier, cancellationToken: cancellationToken);
}
public async IAsyncEnumerable<OpenIddictApplication> FindByPostLogoutRedirectUriAsync(string address, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(address, nameof(address));
var applications = await Repository.FindByPostLogoutRedirectUriAsync(address, includeDetails: true, cancellationToken);
var applications = await Repository.FindByPostLogoutRedirectUriAsync(address, cancellationToken);
foreach (var application in applications)
{
@ -111,7 +97,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
{
Check.NotNullOrEmpty(address, nameof(address));
var applications = await Repository.FindByRedirectUriAsync(address, includeDetails: true, cancellationToken);
var applications = await Repository.FindByRedirectUriAsync(address, cancellationToken);
foreach (var application in applications)
{
var addresses = await GetRedirectUrisAsync(application, cancellationToken);
@ -126,7 +112,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
{
Check.NotNull(query, nameof(query));
return await Repository.GetAsync(query, state, includeDetails: true, cancellationToken);
return await Repository.GetAsync(query, state, cancellationToken);
}
public ValueTask<string> GetClientIdAsync(OpenIddictApplication application, CancellationToken cancellationToken)
@ -400,7 +386,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
public async IAsyncEnumerable<OpenIddictApplication> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var applications = await Repository.ListAsync(count, offset, includeDetails: true, cancellationToken);
var applications = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var application in applications)
{
yield return application;
@ -411,7 +397,7 @@ public class AbpOpenIddictApplicationStore : AbpOpenIddictStoreBase<IOpenIddictA
{
Check.NotNull(query, nameof(query));
var applications = await Repository.ListAsync(query, state, includeDetails: true, cancellationToken);
var applications = await Repository.ListAsync(query, state, cancellationToken);
foreach (var application in applications)
{
yield return application;

@ -11,15 +11,15 @@ public interface IOpenIddictApplicationRepository : IBasicRepository<OpenIddictA
{
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<OpenIddictApplication> FindByClientIdAsync(string clientId, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
}

@ -1,18 +1,10 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.OpenIddict.Authorizations;
using Volo.Abp.OpenIddict.Tokens;
namespace Volo.Abp.OpenIddict.Applications;
public class OpenIddictApplication : FullAuditedAggregateRoot<Guid>
{
/// <summary>
/// Gets the list of the authorizations associated with this application.
/// </summary>
public virtual ICollection<OpenIddictAuthorization> Authorizations { get; } = new HashSet<OpenIddictAuthorization>();
/// <summary>
/// Gets or sets the client identifier associated with the current application.
/// </summary>
@ -72,11 +64,6 @@ public class OpenIddictApplication : FullAuditedAggregateRoot<Guid>
/// </summary>
public virtual string Requirements { get; set; }
/// <summary>
/// Gets the list of the tokens associated with this application.
/// </summary>
public virtual ICollection<OpenIddictToken> Tokens { get; } = new HashSet<OpenIddictToken>();
/// <summary>
/// Gets or sets the application type associated with the current application.
/// </summary>

@ -16,10 +16,6 @@ using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Authorizations;
[ExposeServices(
typeof(IOpenIddictAuthorizationStore<OpenIddictAuthorization>),
typeof(AbpOpenIddictAuthorizationStore)
)]
public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddictAuthorizationRepository>, IOpenIddictAuthorizationStore<OpenIddictAuthorization>, IScopedDependency
{
protected IOpenIddictApplicationRepository ApplicationRepository { get; }
@ -62,10 +58,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true, isolationLevel: IsolationLevel.RepeatableRead))
{
if (authorization.Tokens.Any())
{
await TokenRepository.DeleteManyAsync(authorization.Tokens, cancellationToken: cancellationToken);
}
await TokenRepository.DeleteManyByAuthorizationIdAsync(authorization.Id, cancellationToken: cancellationToken);
await Repository.DeleteAsync(authorization, cancellationToken: cancellationToken);
@ -78,7 +71,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), includeDetails: true, cancellationToken);
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -91,7 +84,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, includeDetails: true, cancellationToken);
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -105,7 +98,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, includeDetails: true, cancellationToken);
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -119,7 +112,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, includeDetails: true, cancellationToken);
var authorizations = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var authorization in authorizations)
{
@ -134,7 +127,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var authorizations = await Repository.FindByApplicationIdAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
var authorizations = await Repository.FindByApplicationIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -145,14 +138,14 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictAuthorization> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
var authorizations = await Repository.FindBySubjectAsync(subject, includeDetails: true, cancellationToken);
var authorizations = await Repository.FindBySubjectAsync(subject, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -172,7 +165,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
{
Check.NotNull(query, nameof(query));
return await Repository.GetAsync(query, state, includeDetails: true, cancellationToken);
return await Repository.GetAsync(query, state, cancellationToken);
}
public virtual ValueTask <DateTimeOffset?> GetCreationDateAsync(OpenIddictAuthorization authorization, CancellationToken cancellationToken)
@ -294,7 +287,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
public virtual async IAsyncEnumerable<OpenIddictAuthorization> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var authorizations = await Repository.ListAsync(count, offset, includeDetails: true, cancellationToken);
var authorizations = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -303,7 +296,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
public virtual async IAsyncEnumerable<TResult> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var authorizations = await Repository.ListAsync(query, state, includeDetails: true, cancellationToken);
var authorizations = await Repository.ListAsync(query, state, cancellationToken);
foreach (var authorization in authorizations)
{
yield return authorization;
@ -320,7 +313,7 @@ public class AbpOpenIddictAuthorizationStore : AbpOpenIddictStoreBase<IOpenIddic
{
var date = threshold.UtcDateTime;
var authorizations = await Repository.GetPruneListAsync(date, 1_000, includeDetails: false, cancellationToken);
var authorizations = await Repository.GetPruneListAsync(date, 1_000, cancellationToken);
if (!authorizations.Any())
{
break;

@ -11,23 +11,23 @@ public interface IOpenIddictAuthorizationRepository : IBasicRepository<OpenIddic
{
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default);
Task<OpenIddictAuthorization> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OpenIddictAuthorization> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default);
}

@ -1,17 +1,10 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.OpenIddict.Tokens;
namespace Volo.Abp.OpenIddict.Authorizations;
public class OpenIddictAuthorization : FullAuditedEntity<Guid>, IHasConcurrencyStamp
public class OpenIddictAuthorization : FullAuditedAggregateRoot<Guid>
{
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }
/// <summary>
/// Gets or sets the application associated with the current authorization.
/// </summary>
@ -44,11 +37,6 @@ public class OpenIddictAuthorization : FullAuditedEntity<Guid>, IHasConcurrencyS
/// </summary>
public virtual string Subject { get; set; }
/// <summary>
/// Gets the list of tokens associated with the current authorization.
/// </summary>
public virtual ICollection<OpenIddictToken> Tokens { get; } = new HashSet<OpenIddictToken>();
/// <summary>
/// Gets or sets the type of the current authorization.
/// </summary>

@ -14,10 +14,6 @@ using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Scopes;
[ExposeServices(
typeof(IOpenIddictScopeStore<OpenIddictScope>),
typeof(AbpOpenIddictScopeStore)
)]
public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRepository>, IOpenIddictScopeStore<OpenIddictScope>, IScopedDependency
{
public AbpOpenIddictScopeStore(
@ -59,14 +55,14 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
}
public virtual async ValueTask<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(name, nameof(name));
return await Repository.FindByNameAsync(name, includeDetails: true, cancellationToken);
return await Repository.FindByNameAsync(name, cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictScope> FindByNamesAsync(ImmutableArray<string> names, [EnumeratorCancellation] CancellationToken cancellationToken)
@ -77,7 +73,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
Check.NotNullOrEmpty(name, nameof(name));
}
var scopes = await Repository.FindByNamesAsync(names.ToArray(), includeDetails: true, cancellationToken);
var scopes = await Repository.FindByNamesAsync(names.ToArray(), cancellationToken);
foreach (var scope in scopes)
{
yield return scope;
@ -88,7 +84,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
{
Check.NotNullOrEmpty(resource, nameof(resource));
var scopes = await Repository.FindByResourceAsync(resource, includeDetails: true, cancellationToken);
var scopes = await Repository.FindByResourceAsync(resource, cancellationToken);
foreach (var scope in scopes)
{
var resources = await GetResourcesAsync(scope, cancellationToken);
@ -101,7 +97,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
public virtual async ValueTask<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken)
{
return await Repository.GetAsync(query, state, includeDetails: true, cancellationToken);
return await Repository.GetAsync(query, state, cancellationToken);
}
public virtual ValueTask<string> GetDescriptionAsync(OpenIddictScope scope, CancellationToken cancellationToken)
@ -288,7 +284,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
public virtual async IAsyncEnumerable<OpenIddictScope> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var scopes = await Repository.ListAsync(count, offset, includeDetails: true, cancellationToken);
var scopes = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var scope in scopes)
{
yield return scope;
@ -299,7 +295,7 @@ public class AbpOpenIddictScopeStore : AbpOpenIddictStoreBase<IOpenIddictScopeRe
{
Check.NotNull(query, nameof(query));
var scopes = await Repository.ListAsync(query, state, includeDetails: true, cancellationToken);
var scopes = await Repository.ListAsync(query, state, cancellationToken);
foreach (var scope in scopes)
{
yield return scope;

@ -11,17 +11,17 @@ public interface IOpenIddictScopeRepository : IBasicRepository<OpenIddictScope,
{
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<OpenIddictScope> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<OpenIddictScope> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> FindByResourceAsync(string resource, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
}

@ -16,10 +16,6 @@ using Volo.Abp.Uow;
namespace Volo.Abp.OpenIddict.Tokens;
[ExposeServices(
typeof(IOpenIddictTokenStore<OpenIddictToken>),
typeof(AbpOpenIddictTokenStore)
)]
public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRepository>, IOpenIddictTokenStore<OpenIddictToken>, IScopedDependency
{
protected IOpenIddictApplicationRepository ApplicationRepository { get; }
@ -66,7 +62,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
Check.NotNullOrEmpty(subject, nameof(subject));
Check.NotNullOrEmpty(client, nameof(client));
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), includeDetails: true, cancellationToken);
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -79,7 +75,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
Check.NotNullOrEmpty(client, nameof(client));
Check.NotNullOrEmpty(status, nameof(status));
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, includeDetails: true, cancellationToken);
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -93,7 +89,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
Check.NotNullOrEmpty(status, nameof(status));
Check.NotNullOrEmpty(type, nameof(type));
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, includeDetails: true, cancellationToken);
var tokens = await Repository.FindAsync(subject, ConvertIdentifierFromString(client), status, type, cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -104,7 +100,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var tokens = await Repository.FindByApplicationIdAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
var tokens = await Repository.FindByApplicationIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -115,7 +111,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
var tokens = await Repository.FindByAuthorizationIdAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
var tokens = await Repository.FindByAuthorizationIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -126,21 +122,21 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), includeDetails: true, cancellationToken);
return await Repository.FindByIdAsync(ConvertIdentifierFromString(identifier), cancellationToken);
}
public virtual async ValueTask<OpenIddictToken> FindByReferenceIdAsync(string identifier, CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(identifier, nameof(identifier));
return await Repository.FindByReferenceIdAsync(identifier, includeDetails: true, cancellationToken);
return await Repository.FindByReferenceIdAsync(identifier, cancellationToken);
}
public virtual async IAsyncEnumerable<OpenIddictToken> FindBySubjectAsync(string subject, [EnumeratorCancellation] CancellationToken cancellationToken)
{
Check.NotNullOrEmpty(subject, nameof(subject));
var tokens = await Repository.FindBySubjectAsync(subject, includeDetails: true, cancellationToken);
var tokens = await Repository.FindBySubjectAsync(subject, cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -160,7 +156,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
Check.NotNull(query, nameof(query));
return await Repository.GetAsync(query, state, includeDetails: true, cancellationToken);
return await Repository.GetAsync(query, state, cancellationToken);
}
public virtual ValueTask<string> GetAuthorizationIdAsync(OpenIddictToken token, CancellationToken cancellationToken)
@ -295,7 +291,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
public virtual async IAsyncEnumerable<OpenIddictToken> ListAsync(int? count, int? offset, [EnumeratorCancellation] CancellationToken cancellationToken)
{
var tokens = await Repository.ListAsync(count, offset, includeDetails: true, cancellationToken);
var tokens = await Repository.ListAsync(count, offset, cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -306,7 +302,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
Check.NotNull(query, nameof(query));
var tokens = await Repository.ListAsync(query, state, includeDetails: true, cancellationToken);
var tokens = await Repository.ListAsync(query, state, cancellationToken);
foreach (var token in tokens)
{
yield return token;
@ -323,7 +319,7 @@ public class AbpOpenIddictTokenStore : AbpOpenIddictStoreBase<IOpenIddictTokenRe
{
var date = threshold.UtcDateTime;
var tokens = await Repository.GetPruneListAsync(date, 1_000, includeDetails: true, cancellationToken);
var tokens = await Repository.GetPruneListAsync(date, 1_000, cancellationToken);
if (!tokens.Any())
{
break;

@ -9,29 +9,33 @@ namespace Volo.Abp.OpenIddict.Tokens;
public interface IOpenIddictTokenRepository : IBasicRepository<OpenIddictToken, Guid>
{
Task DeleteManyByApplicationIdAsync(Guid applicationId, bool autoSave = false, CancellationToken cancellationToken = default);
Task DeleteManyByAuthorizationIdAsync(Guid authorizationId, bool autoSave = false, CancellationToken cancellationToken = default);
Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default);
Task<OpenIddictToken> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OpenIddictToken> FindByIdAsync(Guid id, CancellationToken cancellationToken = default);
Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, bool includeDetails = true, CancellationToken cancellationToken = default);
Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default);
}

@ -1,27 +1,10 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Authorizations;
namespace Volo.Abp.OpenIddict.Tokens;
/* TODO: Reconsider the entity designs
*
* Entity structure seems incorrectly designed:
* `OpenIddictToken` is an entity (not aggregate root) but have its own repository.
* `OpenIddictAuthorization` is also same.
* If they have repositories, they should be aggregate roots and should not be used as navigation properties in other entities (e.g. `OpenIddictApplication`).
* I think this will be the correct way since they are independently queried from database.
*/
public class OpenIddictToken : FullAuditedEntity<Guid>, IHasConcurrencyStamp
public class OpenIddictToken : FullAuditedAggregateRoot<Guid>
{
[DisableAuditing]
public virtual string ConcurrencyStamp { get; set; }
/// <summary>
/// Gets or sets the application associated with the current token.
/// </summary>

@ -19,12 +19,6 @@ public class TokenCleanupBackgroundWorker : AsyncPeriodicBackgroundWorkerBase
protected async override Task DoWorkAsync(PeriodicBackgroundWorkerContext workerContext)
{
/* TODO: Should we use distributed locking here?
* Because, multiple instances of the application may work in parallel, and only one
* of them should work in a time. If you can't obtain the lock, it is good to wait for a longer time.
* I suggest to check https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.EventBus/Volo/Abp/EventBus/Distributed/InboxProcessor.cs
* for a good implementation, then apply a similar principle here.
*/
await workerContext
.ServiceProvider
.GetRequiredService<TokenCleanupService>()

@ -1,31 +0,0 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.OpenIddict.Applications;
using Volo.Abp.OpenIddict.Authorizations;
namespace Volo.Abp.OpenIddict;
public static class AbpOpenIddictEfCoreQueryableExtensions
{
public static IQueryable<OpenIddictApplication> IncludeDetails(this IQueryable<OpenIddictApplication> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
return queryable
.Include(x => x.Authorizations).ThenInclude(x => x.Tokens)
.Include(x => x.Tokens);
}
public static IQueryable<OpenIddictAuthorization> IncludeDetails(this IQueryable<OpenIddictAuthorization> queryable, bool include = true)
{
if (!include)
{
return queryable;
}
return queryable.Include(x => x.Tokens);
}
}

@ -1,27 +0,0 @@
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,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.OpenIddict.EntityFrameworkCore;
namespace Volo.Abp.OpenIddict.Applications;
public class EfCoreOpenIddictApplicationRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictApplication, Guid>, IOpenIddictApplicationRepository
{
public EfCoreOpenIddictApplicationRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.FirstOrDefaultAsync(x => x.ClientId == clientId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.Where(x => x.RedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync(), state)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.OrderBy(x => x.Id)
.SkipIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(offset.HasValue, offset.Value)
.TakeIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(count.HasValue, count.Value)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync(), state)
.ToListAsync(GetCancellationToken(cancellationToken));
}
}

@ -1,81 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.OpenIddict.EntityFrameworkCore;
namespace Volo.Abp.OpenIddict.Applications;
public class OpenIddictApplicationRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictApplication, Guid>, IOpenIddictApplicationRepository
{
public OpenIddictApplicationRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictApplication>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetDbSetAsync()).LongCountAsync(cancellationToken);
}
public virtual async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.FirstOrDefaultAsync(x => x.ClientId == clientId, cancellationToken);
}
public virtual async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(cancellationToken);
}
public virtual async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.RedirectUris.Contains(address)).ToListAsync(cancellationToken);
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await query((await GetDbSetAsync())
.IncludeDetails(includeDetails), state)
.FirstOrDefaultAsync(cancellationToken);
}
public virtual async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.OrderBy(x => x.Id)
.SkipIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(offset.HasValue, offset.Value)
.TakeIf<OpenIddictApplication, IQueryable<OpenIddictApplication>>(count.HasValue, count.Value)
.ToListAsync(cancellationToken);
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await query((await GetDbSetAsync())
.IncludeDetails(includeDetails), state)
.ToListAsync(cancellationToken);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<OpenIddictApplication> WithDetails()
{
return GetQueryable().IncludeDetails();
}
public async override Task<IQueryable<OpenIddictApplication>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();
}
}

@ -11,9 +11,9 @@ using Volo.Abp.OpenIddict.EntityFrameworkCore;
namespace Volo.Abp.OpenIddict.Authorizations;
public class OpenIddictAuthorizationRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictAuthorization, Guid>, IOpenIddictAuthorizationRepository
public class EfCoreOpenIddictAuthorizationRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictAuthorization, Guid>, IOpenIddictAuthorizationRepository
{
public OpenIddictAuthorizationRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
public EfCoreOpenIddictAuthorizationRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
: base(dbContextProvider)
{
@ -21,67 +21,59 @@ public class OpenIddictAuthorizationRepository : EfCoreRepository<IOpenIddictDbC
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictAuthorization>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync()).LongCountAsync(cancellationToken);
return await query(await GetQueryableAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.Subject == subject && x.ApplicationId == client)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.Subject == subject && x.Status == status && x.ApplicationId == client)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.Subject == subject && x.Status == status && x.Type == type && x.ApplicationId == client)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.ApplicationId == applicationId)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictAuthorization> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictAuthorization> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
.FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.Subject == subject)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query((await GetDbSetAsync())
.IncludeDetails(includeDetails), state)
.FirstOrDefaultAsync(cancellationToken);
return await query(await GetDbSetAsync(), state)
.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
var query = (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.OrderBy(authorization => authorization.Id!)
.AsTracking();
@ -95,35 +87,24 @@ public class OpenIddictAuthorizationRepository : EfCoreRepository<IOpenIddictDbC
query = query.Take(count.Value);
}
return await query.ToListAsync(cancellationToken);
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query((await GetDbSetAsync())
.IncludeDetails(includeDetails), state)
.ToListAsync(cancellationToken);
return await query(await GetDbSetAsync(), state)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
var tokenQueryable = (await GetDbContextAsync()).Tokens.AsQueryable();
return await (await GetDbSetAsync())
.IncludeDetails(includeDetails)
.Where(x => x.CreationDate < date)
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !x.Tokens.Any()))
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid ||
(x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && tokenQueryable.Any(t => t.AuthorizationId == x.Id)))
.OrderBy(x => x.Id)
.Take(count)
.ToListAsync(cancellationToken);
}
[Obsolete("Use WithDetailsAsync method.")]
public override IQueryable<OpenIddictAuthorization> WithDetails()
{
return GetQueryable().IncludeDetails();
}
public async override Task<IQueryable<OpenIddictAuthorization>> WithDetailsAsync()
{
return (await GetQueryableAsync()).IncludeDetails();
.ToListAsync(GetCancellationToken(cancellationToken));
}
}

@ -20,10 +20,10 @@ public class AbpOpenIddictEntityFrameworkCoreModule : AbpModule
{
options.AddDefaultRepositories<IOpenIddictDbContext>();
options.AddRepository<OpenIddictApplication, OpenIddictApplicationRepository>();
options.AddRepository<OpenIddictAuthorization, OpenIddictAuthorizationRepository>();
options.AddRepository<OpenIddictScope, OpenIddictScopeRepository>();
options.AddRepository<OpenIddictToken, OpenIddictTokenRepository>();
options.AddRepository<OpenIddictApplication, EfCoreOpenIddictApplicationRepository>();
options.AddRepository<OpenIddictAuthorization, EfCoreOpenIddictAuthorizationRepository>();
options.AddRepository<OpenIddictScope, EfCoreOpenIddictScopeRepository>();
options.AddRepository<OpenIddictToken, EfCoreOpenIddictTokenRepository>();
});
}
}

@ -38,16 +38,6 @@ public static class OpenIddictDbContextModelCreatingExtensions
b.Property(x => x.Type)
.HasMaxLength(OpenIddictApplicationConsts.TypeMaxLength);
b.HasMany(x => x.Authorizations)
.WithOne()
.HasForeignKey(x => x.ApplicationId)
.IsRequired(required: false);
b.HasMany(x => x.Tokens)
.WithOne()
.HasForeignKey(x => x.ApplicationId)
.IsRequired(required: false);
b.ApplyObjectExtensionMappings();
});
@ -74,10 +64,7 @@ public static class OpenIddictDbContextModelCreatingExtensions
b.Property(x => x.Type)
.HasMaxLength(OpenIddictAuthorizationConsts.TypeMaxLength);
b.HasMany(x => x.Tokens)
.WithOne()
.HasForeignKey(x => x.AuthorizationId)
.IsRequired(required: false);
b.HasOne<OpenIddictApplication>().WithMany().HasForeignKey(x => x.ApplicationId).IsRequired(false);
b.ApplyObjectExtensionMappings();
});
@ -126,6 +113,9 @@ public static class OpenIddictDbContextModelCreatingExtensions
b.Property(x => x.Type)
.HasMaxLength(OpenIddictTokenConsts.TypeMaxLength);
b.HasOne<OpenIddictApplication>().WithMany().HasForeignKey(x => x.ApplicationId).IsRequired(false);
b.HasOne<OpenIddictAuthorization>().WithMany().HasForeignKey(x => x.AuthorizationId).IsRequired(false);
b.ApplyObjectExtensionMappings();
});

@ -10,9 +10,9 @@ using Volo.Abp.OpenIddict.EntityFrameworkCore;
namespace Volo.Abp.OpenIddict.Scopes;
public class OpenIddictScopeRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictScope, Guid>, IOpenIddictScopeRepository
public class EfCoreOpenIddictScopeRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictScope, Guid>, IOpenIddictScopeRepository
{
public OpenIddictScopeRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
public EfCoreOpenIddictScopeRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
: base(dbContextProvider)
{
@ -20,45 +20,45 @@ public class OpenIddictScopeRepository : EfCoreRepository<IOpenIddictDbContext,
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictScope>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync()).LongCountAsync(cancellationToken);
return await query(await GetQueryableAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictScope> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Name == name, cancellationToken);
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => names.Contains(x.Name)).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => names.Contains(x.Name)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Resources.Contains(resource)).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.Resources.Contains(resource)).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).FirstOrDefaultAsync(cancellationToken);
return await query(await GetQueryableAsync(), state).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync())
.OrderBy(x => x.Id)
.SkipIf<OpenIddictScope, IQueryable<OpenIddictScope>>(offset.HasValue, offset.Value)
.TakeIf<OpenIddictScope, IQueryable<OpenIddictScope>>(count.HasValue, count.Value)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).ToListAsync(cancellationToken);
return await query(await GetQueryableAsync(), state).ToListAsync(GetCancellationToken(cancellationToken));
}
}

@ -12,81 +12,98 @@ using Volo.Abp.OpenIddict.EntityFrameworkCore;
namespace Volo.Abp.OpenIddict.Tokens;
public class OpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictToken, Guid>, IOpenIddictTokenRepository
public class EfCoreOpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbContext, OpenIddictToken, Guid>, IOpenIddictTokenRepository
{
public OpenIddictTokenRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
public EfCoreOpenIddictTokenRepository(IDbContextProvider<IOpenIddictDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task DeleteManyByApplicationIdAsync(Guid applicationId, bool autoSave = false, CancellationToken cancellationToken = default)
{
var tokens = await (await GetDbSetAsync())
.Where(x => x.ApplicationId == applicationId)
.ToListAsync(GetCancellationToken(cancellationToken));
await DeleteManyAsync(tokens, autoSave, cancellationToken);
}
public async Task DeleteManyByAuthorizationIdAsync(Guid authorizationId, bool autoSave = false, CancellationToken cancellationToken = default)
{
var tokens = await (await GetDbSetAsync())
.Where(x => x.AuthorizationId == authorizationId)
.ToListAsync(GetCancellationToken(cancellationToken));
await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken));
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).LongCountAsync(cancellationToken);
return await (await GetQueryableAsync()).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client && x.Status == status).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client && x.Status == status).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client && x.Status == status && x.Type == type).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.Subject == subject && x.ApplicationId == client && x.Status == status && x.Type == type).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.ApplicationId == applicationId).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.ApplicationId == applicationId).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.AuthorizationId == authorizationId).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.AuthorizationId == authorizationId).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictToken> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictToken> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Id == id, cancellationToken);
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, cancellationToken);
return await (await GetQueryableAsync()).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync()).Where(x => x.Subject == subject).ToListAsync(cancellationToken);
return await (await GetQueryableAsync()).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).FirstOrDefaultAsync(cancellationToken);
return await query(await GetQueryableAsync(), state).FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetQueryableAsync())
.OrderBy(x => x.Id)
.SkipIf<OpenIddictToken, IQueryable<OpenIddictToken>>(offset.HasValue, offset.Value)
.TakeIf<OpenIddictToken, IQueryable<OpenIddictToken>>(count.HasValue, count.Value)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetQueryableAsync(), state).ToListAsync(cancellationToken);
return await query(await GetQueryableAsync(), state).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
//TODO: Test & Improve?
return await (from token in await GetQueryableAsync()
join authorization in (await GetDbContextAsync()).Set<OpenIddictAuthorization>().AsQueryable()
on token.AuthorizationId equals authorization.Id into ta
@ -97,6 +114,7 @@ public class OpenIddictTokenRepository : EfCoreRepository<IOpenIddictDbContext,
(a != null && a.Status != OpenIddictConstants.Statuses.Valid) ||
token.ExpirationDate < DateTime.UtcNow
orderby token.Id
select token).Take(count).ToListAsync(cancellationToken);
select token).Take(count)
.ToListAsync(GetCancellationToken(cancellationToken));
}
}

@ -24,28 +24,28 @@ public class MongoOpenIddictApplicationRepository : MongoDbRepository<OpenIddict
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<OpenIddictApplication> FindByClientIdAsync(string clientId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.FirstOrDefaultAsync(x => x.ClientId == clientId, cancellationToken);
}
public async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<List<OpenIddictApplication>> FindByPostLogoutRedirectUriAsync(string address, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.PostLogoutRedirectUris.Contains(address)).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<List<OpenIddictApplication>> FindByRedirectUriAsync(string address, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<List<OpenIddictApplication>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
.OrderBy(x => x.Id)
@ -55,7 +55,7 @@ public class MongoOpenIddictApplicationRepository : MongoDbRepository<OpenIddict
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictApplication>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}

@ -9,6 +9,7 @@ using OpenIddict.Abstractions;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
using Volo.Abp.OpenIddict.MongoDB;
using Volo.Abp.OpenIddict.Tokens;
namespace Volo.Abp.OpenIddict.Authorizations;
@ -23,68 +24,70 @@ public class MongoOpenIddictAuthorizationRepository : MongoDbRepository<OpenIddi
return await query(await GetMongoQueryableAsync(cancellationToken)).As<IMongoQueryable<OpenIddictAuthorization>>().LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.ApplicationId == applicationId).ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).Where(x => x.ApplicationId == applicationId).ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictAuthorization> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictAuthorization> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.Subject == subject).ToListAsync(GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
return await (await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictAuthorization>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(cancellationToken);
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictAuthorization>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
var tokenQueryable = await GetMongoQueryableAsync<OpenIddictToken>(GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.CreationDate < date)
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid || (x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && !x.Tokens.Any()))
.Where(x => x.Status != OpenIddictConstants.Statuses.Valid ||
(x.Type == OpenIddictConstants.AuthorizationTypes.AdHoc && tokenQueryable.Any(t => t.AuthorizationId == x.Id)))
.OrderBy(x => x.Id)
.Take(count)
.ToListAsync(cancellationToken);
.ToListAsync(GetCancellationToken(cancellationToken));
}
}

@ -22,46 +22,46 @@ public class MongoOpenIddictScopeRepository : MongoDbRepository<OpenIddictMongoD
return await query(await GetMongoQueryableAsync(cancellationToken)).As<IMongoQueryable<OpenIddictScope>>().LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictScope> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictScope> FindByNameAsync(string name, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictScope> FindByNameAsync(string name, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Name == name, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictScope>> FindByNamesAsync(string[] names, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictScope>> FindByResourceAsync(string resource, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictScope>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await Queryable.OrderBy((await GetMongoQueryableAsync(cancellationToken)), x => x.Id)
return await Queryable.OrderBy((await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictScope>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
}

@ -19,86 +19,105 @@ public class MongoOpenIddictTokenRepository : MongoDbRepository<OpenIddictMongoD
{
}
public async Task DeleteManyByApplicationIdAsync(Guid applicationId, bool autoSave = false,
CancellationToken cancellationToken = default)
{
var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.ApplicationId == applicationId)
.ToListAsync(GetCancellationToken(cancellationToken));
await DeleteManyAsync(tokens, autoSave, cancellationToken);
}
public async Task DeleteManyByAuthorizationIdAsync(Guid authorizationId, bool autoSave = false,
CancellationToken cancellationToken = default)
{
var tokens = await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.Where(x => x.ApplicationId == authorizationId)
.ToListAsync(GetCancellationToken(cancellationToken));
await DeleteManyAsync(tokens, autoSave, GetCancellationToken(cancellationToken));
}
public virtual async Task<long> CountAsync<TResult>(Func<IQueryable<OpenIddictToken>, IQueryable<TResult>> query, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).LongCountAsync(GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).LongCountAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, CancellationToken cancellationToken = default)
{
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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client && x.Status == status)
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindAsync(string subject, Guid client, string status, string type, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject && x.ApplicationId == client && x.Status == status && x.Type == type)
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindByApplicationIdAsync(Guid applicationId, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.ApplicationId == applicationId)
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.ApplicationId == applicationId)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindByAuthorizationIdAsync(Guid authorizationId, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.AuthorizationId == authorizationId)
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))), x => x.AuthorizationId == authorizationId)
.As<IMongoQueryable<OpenIddictToken>>()
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictToken> FindByIdAsync(Guid id, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictToken> FindByIdAsync(Guid id, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.Id == id, GetCancellationToken(cancellationToken));
}
public virtual async Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<OpenIddictToken> FindByReferenceIdAsync(string referenceId, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, GetCancellationToken(cancellationToken));
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))).FirstOrDefaultAsync(x => x.ReferenceId == referenceId, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> FindBySubjectAsync(string subject, CancellationToken cancellationToken = default)
{
return await Queryable.Where((await GetMongoQueryableAsync(cancellationToken)), x => x.Subject == subject)
return await Queryable.Where((await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<TResult> GetAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<OpenIddictToken>> ListAsync(int? count, int? offset, CancellationToken cancellationToken = default)
{
return await Queryable.OrderBy((await GetMongoQueryableAsync(cancellationToken)), x => x.Id)
return await Queryable.OrderBy((await GetMongoQueryableAsync(GetCancellationToken(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, bool includeDetails = true, CancellationToken cancellationToken = default)
public virtual async Task<List<TResult>> ListAsync<TState, TResult>(Func<IQueryable<OpenIddictToken>, TState, IQueryable<TResult>> query, TState state, CancellationToken cancellationToken = default)
{
return await query(await GetMongoQueryableAsync(cancellationToken), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
return await query(await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)), state).As<IMongoQueryable<TResult>>().ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, bool includeDetails = true, CancellationToken cancellationToken = default)
public async Task<List<OpenIddictToken>> GetPruneListAsync(DateTime date, int count, CancellationToken cancellationToken = default)
{
//TODO: Test & Improve?
return await (from token in await GetMongoQueryableAsync(cancellationToken)
return await (from token in await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))
join authorization in (await GetMongoQueryableAsync<OpenIddictAuthorization>(cancellationToken))
on token.AuthorizationId equals authorization.Id into ta
from a in ta

@ -1,3 +0,0 @@
* AbpOpenIddictStoreBase.Cache is IMemoryCache. Is that proper?
* As I see, we've implemented all the flows, but we intended to make some of these with abp commercial? Don't make any change yet, but we will consider it again.
Loading…
Cancel
Save