Skip to content

[Bug]: Authentication problem with 6.6.2  #2939

@kenwonders

Description

@kenwonders

Describe the bug

Upgrading from 6.50 to 6.6.2 caused our authentication system to stop working. We have a separate identity server using client credentials and with 6.6.2 we are always getting the error:

swashbuckle error

Reverting just Swashbuckle.AspNetCore back to 6.5.0 resolves the issue.

Our .AddSwaggerGen code:

                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Type = SecuritySchemeType.OAuth2,
                    Flows = new OpenApiOAuthFlows
                    {
                        ClientCredentials = new OpenApiOAuthFlow
                        {
                            TokenUrl = new Uri(Configuration["Identity:Authority"] + "/connect/token"),
                            Scopes = new Dictionary<string, string>
                            {
                                { "***.User", "" },
                                { "***.Admin", "" }
                            },
                            AuthorizationUrl = new Uri(Configuration["Identity:Authority"] + "/oauth2/authorize"),
                        }
                    }
                });
                c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Id = "Bearer",
                                Type = ReferenceType.SecurityScheme
                            }
                        },
                        new List<string>()
                    }
                });

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
                .AddJwtBearer(o =>
                {                    
                    o.Authority = Configuration["Identity:Authority"];
                    o.RequireHttpsMetadata = bool.Parse(Configuration["Identity:RequireHttpsMetadata"]);
                    o.Audience = Configuration["Identity:Audience"];
                    o.TokenValidationParameters = new TokenValidationParameters { ValidateAudience = bool.Parse(Configuration["Identity:ValidateAudience"]) };                                        
                });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("***", policy => policy.RequireClaim("client_Role", "***", "***"));
                options.AddPolicy("***", policy => policy.RequireClaim("client_Role", "***"));
            });

In our UseSwaggerUI:

                C.UseRequestInterceptor("" +
                    "(req) => { if (req.url.endsWith('connect/token') && req.body)" +
                    " req.body += '&client_id=' + client_id.value + '&client_secret=' + client_secret.value; return req; }");

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.6.2

.NET Version

NET8

Anything else?

If there's any other information you need please let me know.

Metadata

Metadata

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions