Skip to content

Commit

Permalink
Merge pull request abpframework#16168 from abpframework/AttachScopes
Browse files Browse the repository at this point in the history
Add `AttachScopes` handler.
  • Loading branch information
realLiangshiwei authored Apr 4, 2023
2 parents eb8c79e + 783e38f commit f52e613
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("uniqueidentifier")
.HasColumnName("LastModifierId");

b.Property<DateTimeOffset?>("LastPasswordChangeTime")
.HasColumnType("datetimeoffset");

b.Property<bool>("LockoutEnabled")
.ValueGeneratedOnAdd()
.HasColumnType("bit")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;

Expand Down Expand Up @@ -133,6 +134,7 @@ private void AddOpenIddictServer(IServiceCollection services)
}

builder.AddEventHandler(RemoveClaimsFromClientCredentialsGrantType.Descriptor);
builder.AddEventHandler(AttachScopes.Descriptor);

services.ExecutePreConfiguredActions(builder);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit f52e613

Please sign in to comment.