Browse Source

Add `AttachScopes` handler.

Resolve #16141
pull/16168/head
maliming 4 years ago
parent
commit
783e38f556
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 5
      modules/openiddict/app/OpenIddict.Demo.Server/Migrations/20230404033745_Initial.Designer.cs
  2. 1
      modules/openiddict/app/OpenIddict.Demo.Server/Migrations/20230404033745_Initial.cs
  3. 3
      modules/openiddict/app/OpenIddict.Demo.Server/Migrations/ServerDbContextModelSnapshot.cs
  4. 2
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs
  5. 34
      modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Scopes/AttachScopes.cs

5
modules/openiddict/app/OpenIddict.Demo.Server/Migrations/20230307054116_Initial.Designer.cs → modules/openiddict/app/OpenIddict.Demo.Server/Migrations/20230404033745_Initial.Designer.cs

@ -13,7 +13,7 @@ using Volo.Abp.EntityFrameworkCore;
namespace OpenIddict.Demo.Server.Migrations
{
[DbContext(typeof(ServerDbContext))]
[Migration("20230307054116_Initial")]
[Migration("20230404033745_Initial")]
partial class Initial
{
/// <inheritdoc />
@ -455,6 +455,9 @@ namespace OpenIddict.Demo.Server.Migrations
.HasColumnType("uniqueidentifier")
.HasColumnName("LastModifierId");
b.Property<DateTimeOffset?>("LastPasswordChangeTime")
.HasColumnType("datetimeoffset");
b.Property<bool>("LockoutEnabled")
.ValueGeneratedOnAdd()
.HasColumnType("bit")

1
modules/openiddict/app/OpenIddict.Demo.Server/Migrations/20230307054116_Initial.cs → modules/openiddict/app/OpenIddict.Demo.Server/Migrations/20230404033745_Initial.cs

@ -283,6 +283,7 @@ namespace OpenIddict.Demo.Server.Migrations
AccessFailedCount = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
ShouldChangePasswordOnNextLogin = table.Column<bool>(type: "bit", nullable: false),
EntityVersion = table.Column<int>(type: "int", nullable: false),
LastPasswordChangeTime = table.Column<DateTimeOffset>(type: "datetimeoffset", 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),

3
modules/openiddict/app/OpenIddict.Demo.Server/Migrations/ServerDbContextModelSnapshot.cs

@ -452,6 +452,9 @@ namespace OpenIddict.Demo.Server.Migrations
.HasColumnType("uniqueidentifier")
.HasColumnName("LastModifierId");
b.Property<DateTimeOffset?>("LastPasswordChangeTime")
.HasColumnType("datetimeoffset");
b.Property<bool>("LockoutEnabled")
.ValueGeneratedOnAdd()
.HasColumnType("bit")

2
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/AbpOpenIddictAspNetCoreModule.cs

@ -5,6 +5,7 @@ using OpenIddict.Server;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared;
using Volo.Abp.Modularity;
using Volo.Abp.OpenIddict.Scopes;
using Volo.Abp.OpenIddict.WildcardDomains;
using Volo.Abp.Security.Claims;
@ -133,6 +134,7 @@ public class AbpOpenIddictAspNetCoreModule : AbpModule
}
builder.AddEventHandler(RemoveClaimsFromClientCredentialsGrantType.Descriptor);
builder.AddEventHandler(AttachScopes.Descriptor);
services.ExecutePreConfiguredActions(builder);
});

34
modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/Scopes/AttachScopes.cs

@ -0,0 +1,34 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using OpenIddict.Server;
namespace Volo.Abp.OpenIddict.Scopes;
public class AttachScopes : IOpenIddictServerHandler<OpenIddictServerEvents.HandleConfigurationRequestContext>
{
public static OpenIddictServerHandlerDescriptor Descriptor { get; }
= OpenIddictServerHandlerDescriptor.CreateBuilder<OpenIddictServerEvents.HandleConfigurationRequestContext>()
.UseSingletonHandler<AttachScopes>()
.SetOrder(OpenIddictServerHandlers.Discovery.AttachScopes.Descriptor.Order + 1)
.SetType(OpenIddictServerHandlerType.Custom)
.Build();
private readonly IOpenIddictScopeRepository _scopeRepository;
public AttachScopes(IOpenIddictScopeRepository scopeRepository)
{
_scopeRepository = scopeRepository;
}
public async ValueTask HandleAsync(OpenIddictServerEvents.HandleConfigurationRequestContext context)
{
if (context is null)
{
throw new ArgumentNullException(nameof(context));
}
var scopes = await _scopeRepository.GetListAsync();
context.Scopes.UnionWith(scopes.Select(x => x.Name));
}
}
Loading…
Cancel
Save