Add `AttachScopes` handler.

Resolve #16141
pull/16168/head
maliming 3 years ago
parent eb8c79e723
commit 783e38f556
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4

@ -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")

@ -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),

@ -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")

@ -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);
});

@ -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