Contributions
Blazor WASM aspnetcore hosted app - need Swagger configuration for Server project with Authorization
Using the VS2019 template which I believe has IdentityServer 4.0 I have already added the standard Swagger configurations to Startup.cs: public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer( Configuration.GetConnectionString("DefaultConnection"))); var dataConnectionString = Configuration.GetConnectionString("DataConnection"); services.AddDbContext<SchoolDBContext>(option => option.UseSqlServer(dataConnectionString)); var timeConnectionString = Configuration.GetConnectionString("TimeConnection"); services.AddDbContext<TKContext>(option => option.UseSqlServer(timeConnectionString)); services.AddCors(o => o.AddPolicy("Policy", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.Configure<IdentityOptions>(options => options.ClaimsIdentity.UserIdClaimType = ClaimTypes.NameIdentifier); services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = false) .AddRoles<IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>(); services.AddIdentityServer() .AddApiAuthorization<ApplicationUser, ApplicationDbContext>(); services.AddAuthentication() .AddIdentityServerJwt(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "AMwAuth", Version = "v1" }); }); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); app.UseWebAssemblyDebugging(); app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AMwAuth v1")); } } I can navigate to the Swagger page and can see the various controllers that are in this project, but when I attempt to Execute an action method there is an error message that indicates it is not configurated to use Authorization. In some search results I see there us an Authorize button visible in the Swagger UI, which I don't have. What configuration items do I need to add to make this work?604Views0likes0Comments