Open Closed

PreConfigure<OpenIddictBuilder> is called twice #8302


User avatar
0
jean@groovejones.com created

The following lambda code:

        PreConfigure<OpenIddictBuilder>(builder =>
        {
            // THIS IS CALLED TWICE
            

            builder.AddValidation(options =>
            {
                options.AddAudiences("AbpSolution1");
                options.UseLocalServer();
                options.UseAspNetCore();
            });
        });

is called twice. This is the code provided by ABP template. This is problematic because I want to attach handler in there and it is being called more than once.

            // If I add this, then my event handler is added twice.
            builder.AddServer(options =>
            {
                options.AllowDeviceCodeFlow();

                options.AddEventHandler(ScanScopedHandler.Descriptor);
            });

Can you please provide a fix or a workaround?

  • UI Type: Angular / MVC /8.3.3
  • Template: app
  • Created ABP Studio Version: 0.9.6
  • Tiered: No
  • UI Framework: mvc
  • Theme: leptonx
  • Theme Style: system
  • Database Provider: ef
  • Database Management System: postgresql
  • Separate Tenant Schema: No
  • Mobile Framework: none
  • Public Website: No
  • Optional Modules:
    • GDPR
    • TextTemplateManagement
    • LanguageManagement
    • AuditLogging
    • SaaS
    • OpenIddictAdmin
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

1 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Fullstack Developer

    Hi,

    We will fix it. https://github.com/abpframework/abp/issues/21377

    you can use this way as a temporary Solution

    public static bool IsOpenIddictBuilderConfigured = false;
        
    public override void PreConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
        var configuration = context.Services.GetConfiguration();
    
        PreConfigure<OpenIddictBuilder>(builder =>
        {
            if (!IsOpenIddictBuilderConfigured)
            {
                builder.AddValidation(options =>
                {
                    options.AddAudiences("Qa");
                    options.UseLocalServer();
                    options.UseAspNetCore();
                });
    
                IsOpenIddictBuilderConfigured = true;
            }
        })
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.