Skip to content

Commit

Permalink
skip authentication for development and stage environment( endpoint t…
Browse files Browse the repository at this point in the history
…esting )
  • Loading branch information
omid-ahmadpour committed Apr 30, 2023
1 parent fdb09bb commit c0487c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Web/Api/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Hosting;

namespace CleanTemplate.Api
{
Expand All @@ -17,6 +18,7 @@ namespace CleanTemplate.Api
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -72,7 +74,8 @@ public static IServiceCollection AddWebApi(this IServiceCollection services, ICo
return services;
}

public static IApplicationBuilder UseWebApi(this IApplicationBuilder app, IConfiguration configuration)
public static IApplicationBuilder UseWebApi(this IApplicationBuilder app, IConfiguration configuration,
IWebHostEnvironment env)
{
app.UseCors(builder =>
{
Expand All @@ -91,7 +94,15 @@ public static IApplicationBuilder UseWebApi(this IApplicationBuilder app, IConfi

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
if (env.IsDevelopment() || env.IsStaging())
{
endpoints.MapControllers().AllowAnonymous();
}
else
{
endpoints.MapControllers();
}
endpoints.MapHealthChecksUI();
endpoints.MapHealthChecks("/health", new HealthCheckOptions()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Web/Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseDeveloperExceptionPage();
}

app.UseWebApi(Configuration);
app.UseWebApi(Configuration, env);
}
}
}

0 comments on commit c0487c2

Please sign in to comment.